Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've written CSV exports in C from scratch, no external dependencies required.

It's "Comma Separated Variables", it doesn't really need anymore specification than that.

These files have always imported into M$ and libre office suites without issue.



Comma Separated Values.

Normally, I wouldn't nitpick (hold for laughter) but this is just a perfect example of how CSV is not CSV and how it's probably impossible to support everything people call CSV, simply because of the tiny (or not so tiny) differences between formats.


It needs more specification than that. Have you read RFC 4180?


oh boy. here's where it breaks

- supporting "" (single)

- Supporting newlines in "", oops, now you can't getline() and instead need to getdelim()

- Supporting comments # (why is this even a thing)

- Supporting multiple "" in a field

- Escaping " with "" or \"

- length based csv, so all fields are seekable.

It's a mess, which one's your csv?


The vast majority of CSVs do not have strings which include either quotes or newlines.

No CSV I have ever encountered has comments.


Google contacts does.


It seems that Google generally try and find ways of making exporting their data to use in other services as painful as possible.


You need newlines in fields, because contacts has addresses, and addresses have newlines. (And also Notes, but that's not as important)

(Oh and I forgot about headers, headers should be mandatory but people are aloof about it)


So you're fine with a lot of bugs in the case of a vast minority?


Well, most code that loads CSVs is intended to work with certain files from certain sources, and not with all the CSVs that have ever existed.

So yes, I am happy with code that works for a subset of files. There are thousands of applications which work with CSVs and they all do exactly this.


and those thousands of apps bug because they exist in a reality where few CSVs from certain sources can have different formats, not in the fantasy world where intention to work with certain files becomes a binding specification




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: