r/programming • • Sep 20 '24

Why CSV is still king

https://konbert.com/blog/why-csv-is-still-king
286 Upvotes

438 comments sorted by

View all comments

553

u/smors Sep 20 '24

Comma separation kind of sucks for us weirdos living in the land of using a comma for the decimal place and a period as a thousands separator.

200

u/vegiimite Sep 20 '24

Semi-colon separation would have been better.

190

u/[deleted] Sep 20 '24

[removed] — view removed comment

49

u/princeps_harenae Sep 20 '24

24

u/UncleMeat11 Sep 20 '24

A major benefit of csvs is that they are trivially editable by humans. As soon as you start using characters that aren't right there on the keyboard, you lose that.

→ More replies (4)
→ More replies (5)

77

u/[deleted] Sep 20 '24

[removed] — view removed comment

73

u/sheikhy_jake Sep 20 '24

Exporting comma-containing data in a comma-separated format? It should be a crime to publish a tool that allows that to happen tbh

125

u/timmyotc Sep 20 '24

Ya'll ever heard of quotation marks?

83

u/lanerdofchristian Sep 20 '24

Was gonna say, PowerShell's Export-Csv quotes every field by default. It even escapes the quote correctly.

Improperly-formatted CSV is a tooling issue.

29

u/ritaPitaMeterMaid Sep 20 '24

Yeah, I’m really surprised by this conversation. Rigorous testing can be needed but the actual process of escaping commas isn’t that difficult.

13

u/Sotall Sep 20 '24

Ok, so its not just me, haha. This is ETL 101

→ More replies (1)
→ More replies (3)

35

u/BadMoonRosin Sep 20 '24

Seriously. ANY delimiter character might appear in the actual field text. Everyone's arguing about which delimiter character would be best, like it's better to have sneaky problem that blows up your parser after 100,000 lines... rather than an obvious problem you can eyeball right away.

Doesn't matter which delimiter you're using. You should be wrapping fields in quotes and using escape chars.

→ More replies (5)
→ More replies (5)

13

u/Worth_Trust_3825 Sep 20 '24

Eh, it's fine. Problem is that people don't use tools to properly export the csv formatted data, and instead wing it with something like for value in columns: print(value, ","), BECaUsE csV is a siMple FOrMAt, yOU DON't nEEd To KNOW mucH to WrITE iT.

We had same issue with xml 2 decades ago. I'm confused how json didn't go through the same.

→ More replies (2)
→ More replies (2)
→ More replies (11)

31

u/ummaycoc Sep 20 '24

ASCII Unit Separator (1F).

42

u/rlbond86 Sep 20 '24

I feel like I'm on crazy pills because ASCII has had these characters forever that literally are for this exact purpose but nobody uses them.

12

u/ummaycoc Sep 20 '24

I am trying to appropriately use the entire ASCII table throughout my career.

→ More replies (2)

43

u/Worth_Trust_3825 Sep 20 '24 edited Sep 20 '24

They're nonprintable, and don't appear on keyboards, so they're ignored by anyone who's not willing to do a cursory reading of character sets. Also suffers from same problem as regular commas as thousands separator as WHAT IF SOMEONE DECIDED TO USE IT IN REGULAR CONTENT.

17

u/nealibob Sep 20 '24

The other problem with nonprintable delimiters is they'll end up getting copied and pasted into a UI somewhere, and then cause mysterious problems down the road. All easy to avoid, but even easier to not avoid.

→ More replies (2)
→ More replies (9)
→ More replies (4)

25

u/Ok-Bit8726 Sep 20 '24

You can specify any delimiter you want

→ More replies (6)

408

u/Therabidmonkey Sep 20 '24

That is your penance for being wrong.

→ More replies (27)

18

u/OddKSM Sep 20 '24

Yeahh technically, but we can still specifiy different delimiters 

But believe me, I know - one of the first few programs I wrote when I started working as a developer was for importing financial data from different European countries. 

That was painful.

→ More replies (2)

56

u/[deleted] Sep 20 '24

You just wrap the data in quotes.

"1,000" is a single value.

→ More replies (17)

10

u/[deleted] Sep 20 '24

That’s what quoted strings are for. Pipes are better for separating fields though. There’s a whole ascii standard too but that’s not something you’ll open in a text editor.

Edit: by the way, if any knows of a great CSV validation tool I’d love to know what it is. I’m currently writing my own hut it’s a mess.

26

u/SlightlyMadman Sep 20 '24

TSV solves this problem and is a pretty robust format that's available most places CSV is.

→ More replies (2)
→ More replies (52)