News for hackers. Stuff that matters.
Re:So you want to write your own CSV code (2014) by atoav on Friday May 15, 2020 @07:27AM (#23190918)
Easy: CSVs are human readable and writeable and humans tend to have a comma sign on their keyboard, while they don't have the ASCII record seperator visible (teaching them to use eg Alt + 30 will not work).

And if they had that key on their keyboard then you'd have the comma problems all over again: What if a ASCII record seperator shows up in the field?

Re:So you want to write your own CSV code (2014) by r00fus on Friday May 15, 2020 @12:41PM (#23194202)
If the ASCII separators were supported regularly in text editors since the early days then it would remove 90% of the problems.

I prefer the | pipe character as a delimiter - easy to see, not part of common speech or titles, and enterable via keyboard. Yes, it can exist in the field but less likely.

Re:So you want to write your own CSV code (2014) by niccl on Friday May 15, 2020 @05:33PM (#23197734)
But if it _might_ turn up, you have to assume it will and deal with it, and then you're into the exact same problem as before, but with something even less 'standard' than before.

I think it's like cryptography. Why bother to roll your own when there are people who are cleverer (certainly than me. I don't know about you) who've already put a lot of effort in to this, so just use one of the well tested standard libraries and don't mess with it

Re:So you want to write your own CSV code (2014) by r00fus on Friday May 15, 2020 @07:03PM (#23198532)
I'm not recommending "rolling your own". You still use CSV libraries, but with a pipe delimiter instead.
Re:So you want to write your own CSV code (2014) by chapium on Friday May 15, 2020 @12:58PM (#23194421)
It looks a LOT like l and I.
Re:So you want to write your own CSV code (2014) by r00fus on Friday May 15, 2020 @05:30PM (#23197701)
Luckily code sees it as ASCII 124. If you're saying that for compliance, | can be converted to l/I then it's a feature, not a downside.
Re:So you want to write your own CSV code (2014) by throwaway_pdp09 on Friday May 15, 2020 @07:53AM (#23191092)
> What if a ASCII record seperator shows up

point is, being not human readable and having no keyboard key, you can reasonably expect those special separators not to.

I suppose I'd consider such special-separated files (26 to 29 from memory?) to be machine generated and machine readable only, not intended as human readable without a bit of extra software or eg. a special emacs mode

Re:So you want to write your own CSV code (2014) by roenxi on Friday May 15, 2020 @08:23AM (#23191298)
You're almost certainly describing a file format that already exists and that nobody uses because it is not human-interactable.

Anyone can edit a csv. I often have. An important feature.

The only real stumper in the CSV format is why they didn't use \ as the escape in strings like everyone else. Probably some good reason.

Re:So you want to write your own CSV code (2014) by eyelidlessness on Friday May 15, 2020 @10:32AM (#23192606)
While backslash escaping is very common, double-quote (or double-special-anything) is fairly common as well. I use it all the time in SQL.
Re:So you want to write your own CSV code (2014) by throwaway_pdp09 on Friday May 15, 2020 @09:07AM (#23191707)
Interesting. I don't think I have ever hand edited a CSV (unless you mean created from scratch, well then, perhaps).

OTOH the ability to just look at it... that I've found very valuable and agree there.

Re:So you want to write your own CSV code (2014) by sokoloff on Friday May 15, 2020 @08:07AM (#23191170)
When considering standard A that can only work with machine generated and machine readable files and standard B that can work with all those files plus human-readable/editable files, I don’t find it surprising at all that standard B wins in the market.
Re:So you want to write your own CSV code (2014) by ken on Friday May 15, 2020 @09:42AM (#23192040)
It happens. XPM/PBM/XBM lost to TIFF (and later PNG). Postscript lost to PDF. OpenOffice.org XML couldn't displace Excel's Binary File Format.

As much as I wish that beauty or usability was the primary indicator of market success, the simpler explanation that explains all of these (including CSV) is: Microsoft Office supported them.

Re:So you want to write your own CSV code (2014) by throwaway_pdp09 on Friday May 15, 2020 @09:47AM (#23192090)
I don't know about XPM/PBM/XBM lost but AIUI PDF is just a subset of postscript with compression. If you think MS's binary excel file format is all that secret, I suggest you try unzipping it - it is no more than compressed XML. I have rescued parts of corrupt excel and word files by doing just that.
Re:So you want to write your own CSV code (2014) by mark-r on Friday May 15, 2020 @11:50AM (#23193598)
MS completely redesigned their binary formats a few years ago. You're right about the current format, but the earlier one was completely undecipherable. Even the current XML has quirks in it to be compatible with the older format.
Re:So you want to write your own CSV code (2014) by mike22 on Sunday May 17, 2020 @03:07PM (#23214414)
It was reversible enough to write the Apache POI library. I maintain code that uses the HSSF streaming API portion of the library, which mainly gives you low-level access to the structures in XLS files. The OO.org folks made some very nice documentation: http://www.openoffice.org/sc/excelfileformat.pdf
Re:So you want to write your own CSV code (2014) by ken on Friday May 15, 2020 @03:32PM (#23196382)
PDF diverged from Postscript years ago.

Microsoft’s binary Excel format is not XML -- you’re thinking of its replacement. It was COM/OLE or some such.

Re:So you want to write your own CSV code (2014) by greggman3 on Friday May 15, 2020 @11:46AM (#23193526)
Binary formats win I think when the ASCII format is significantly greater in storage size and parsing speed. XPM/PBM/XBM are enormous compared to any binary image format. And remember these images used to get put on 1.4meg floppies and sent over 2400baud modems.

It's basically use the right tool for the job. For pixels that's a binary format. For mostly text, text itself works pretty well.

Re:So you want to write your own CSV code (2014) by throwaway_pdp09 on Friday May 15, 2020 @08:20AM (#23191270)
There is no standard but one for CSV files (the RFC 4180 mentioned).

The whole article pretty well rams home the fact there is no standard B because there is no standard which is adhered to.

Re:So you want to write your own CSV code (2014) by sokoloff on Friday May 15, 2020 @08:23AM (#23191300)
Humans are not bound by the computer science definition of “standard”.

But you’re correct that I was using the word “standard” imprecisely to mean something more like “file extension” rather than an IETF RFC.

Re:So you want to write your own CSV code (2014) by ISL on Friday May 15, 2020 @09:42AM (#23192049)
If someone copy-pastes a line from one CSV to a string within a field of another, the second will have record separators from the first within a single field.
Re:So you want to write your own CSV code (2014) by u801e on Friday May 15, 2020 @09:38AM (#23191993)
> CSVs are human readable and writeable and humans tend to have a comma sign on their keyboard

Do people usually compose CSV data by hand? I thought they would use a program like Excel, enter or generate their data in separate cells and then save the file as a CSV. There's no reason why a program like Excel (or any other program for that matter) couldn't use the record separator instead of a comma as a delimiter when generating or consuming such files.

Re:So you want to write your own CSV code (2014) by BiteCode_dev on Friday May 15, 2020 @10:22AM (#23192510)
Compose, rarely. Read and edit with plain text editor, it's common.
Re:So you want to write your own CSV code (2014) by mywittyname on Friday May 15, 2020 @11:50AM (#23193591)
I did it like three times already today.
Re:So you want to write your own CSV code (2014) by u801e on Friday May 15, 2020 @12:04PM (#23193750)
What editor did you use?
Re:So you want to write your own CSV code (2014) by mywittyname on Friday May 15, 2020 @03:52PM (#23196642)
vim / sublime text, depending on context.

I do a lot of troubleshooting using CLI tools like grep and wc.

Re:So you want to write your own CSV code (2014) by ganstyles on Friday May 15, 2020 @09:58AM (#23192233)
I do quite a bit for GitHub markdown tables, for making small annotations for ML, for python parsing, etc. Very common and would be annoying too open up excel every time I needed some csv.
Re:So you want to write your own CSV code (2014) by u801e on Friday May 15, 2020 @12:13PM (#23193845)
I thought markdown tables used the pipe character as the delimiter between table columns.

Also, is not necessary to use excel, and a lot of the issues brought up in the article wouldn't be the case with a different delimiter character. Editors could easily be updated to make entering that delimiter character easier to enter by mapping it to a key like tab whenever a file like that is opened.

It just seems like a problem that could be solved, but can't be due to inertia.

Re:So you want to write your own CSV code (2014) by yiyus on Friday May 15, 2020 @12:37PM (#23194140)
> I thought markdown tables used the pipe character as the delimiter between table columns.

Markdown (the original one by John Gruber) does not include any syntax for tables. Other implementations have included it, but there is no standard. As far as I know, using the pipe character to separate columns is indeed quite common, but it is not the only way.

Re:So you want to write your own CSV code (2014) by Kluny on Friday May 15, 2020 @11:41AM (#23193466)
In my experience, they'll have a database that they administrate through excel, then output it as CSV for whatever tool that needs to process it.
Re:So you want to write your own CSV code (2014) by louis_pasteur on Friday May 15, 2020 @07:30AM (#23190938)
But humans rarely use notepad these days. They use code editors like Coda or VSCode at the very least which have all kinds of advanced features. Surely, those can include support for ASCII separators?
Re:So you want to write your own CSV code (2014) by sfifs on Friday May 15, 2020 @07:59AM (#23191123)
Let's say we have a product master. Something looks fishy and we want a brand person or product supply person to check... Push a CSV and it's trivially easy for them to open in XL and check, make corrections and send.

In a business context, this happens far more often than you may expect. Sure you can build a custom platform to validate and make people connect to a form connecting to a database - but Excel is a great user interface and everyone knows excel.

A funny incident - we were struggling to build a complex workflow in KNIME where at some points we need user input. Nothing out of the box was great - tools either assume a dashboard paradigm or a data flow paradigm - nothing In between.

One of our creative folks came up with the solution of writing to a CSV and getting KNIME to open it in excel. The user would make changes and save, close excel and continue the workflow in KNIME. Even completely non technical people got it.

Re:So you want to write your own CSV code (2014) by hnick on Friday May 15, 2020 @09:20AM (#23191834)
We had to ban our non-technical users from opening CSVs in Excel because it would strip leading zeros and do other exciting things like convert large numbers to 1.23123E+20 :(

It does this without any notification or warning when you save.

Re:So you want to write your own CSV code (2014) by Tostino on Friday May 15, 2020 @01:01PM (#23194468)
Kill me...i've dealt with flat file ETL for ~9 years now, with the first 2 pretty much dedicated to it. I hate hate hate Excel for no reason other than that. It has wasted so many hours due to customers messing up their identifiers by opening up their feeds in Excel prior to sending, and accidentally transforming like above, then having to fix changing customer identifiers used throughout the system once they figure out what happened.
Re:So you want to write your own CSV code (2014) by Semaphor on Friday May 15, 2020 @10:38AM (#23192677)
Excel can only display CSV files. I had to ban myself from editing files in Excel because it’s atrocious at it. It also likes to somewhat change decimal-seperators (again, without any warning).
Re:So you want to write your own CSV code (2014) by Someone on Friday May 15, 2020 @11:18AM (#23193142)
Even technical users have trouble round tripping data to Excel.

https://genomebiology.biomedcentral.com/articles/10.1186/s13...:

“A programmatic scan of leading genomics journals reveals that approximately one-fifth of papers with supplementary Excel gene lists contain erroneous gene name conversions.”

That paper is from 2016, at least 12 years after the problem was first identified.

Re:So you want to write your own CSV code (2014) by mark-r on Friday May 15, 2020 @11:53AM (#23193625)
East coast zip codes with leading zeros are a real problem.
Re:So you want to write your own CSV code (2014) by mywittyname on Friday May 15, 2020 @11:57AM (#23193672)
That behavior is technically correct because those are all valid representations of that value, e.g., 007449938 = 7449938 = 7.449938E6. Pretty much any plain text (or binary) data format will have this same issue, unless it supports additional metadata for display purposes.

If you intended the data to be a string value, then it should have been enclosed in quotes.

Re:So you want to write your own CSV code (2014) by yiyus on Friday May 15, 2020 @12:40PM (#23194180)
The problem is that when you have a number like 123451234512345, it may get rewritten as 1.234512E+14, and then you are loosing information.
Re:So you want to write your own CSV code (2014) by hnick on Friday May 15, 2020 @09:36PM (#23199644)
Your assertion sounded incorrect so I tested it. Quoting large numbers does not preserve them on a save.

Adding a ' before it should work, but for data extracted from arbitrary systems you'll have few guarantees of the sort. Formatting the cells in Excel to display the full value instead of the truncated value also works from memory, but you won't always know ahead of time if this happened later in the file.

In our case it was often mailing identifier barcodes so any loss of precision made them entirely useless.

Re:So you want to write your own CSV code (2014) by rovolo on Friday May 15, 2020 @01:54PM (#23195151)
What if the value is an ID rather than an integer? CSV doesn't specify whether the data type is a string or a number. The schema needs to be inferred by the parser/user.
Re:So you want to write your own CSV code (2014) by recursive on Friday May 15, 2020 @02:19PM (#23195488)
> If you intended the data to be a string value, then it should have been enclosed in quotes.

That's not part of any CSV specification I've seen, including RFC4180.

Re:So you want to write your own CSV code (2014) by SifJar on Friday May 15, 2020 @08:19AM (#23191267)
but if using the ASCII separators was common, excel would support that and it seems like this workflow would be unaffected?
Re:So you want to write your own CSV code (2014) by paulryanrogers on Friday May 15, 2020 @08:31AM (#23191369)
People still need to open them in non-excel apps. And the format may predate widespread use of spreadsheet software.

Fun fact, Excel will truncate numbers beyond 15 digits unless prefixed with a single quote mark.

Re:So you want to write your own CSV code (2014) by the_angry_angel on Friday May 15, 2020 @07:40AM (#23191006)
> But humans rarely use notepad these days. They use code editors like Coda or VSCode at the very least which have all kinds of advanced features. Surely, those can include support for ASCII separators?

I do a fair amount of work with companies that do "EDI" over CSV (or worse CSV-like - think 2 CSVs jammed together with different formats, no headers, no support for escaping or quoting) and fixed width documents. I can absolutely assure you that humans do open these files in notepad far more often than I'd like.

Often one of the main reasons they don't use things like X12, ASCII separators, etc. is because a "human needs to open it at some point" was a prevailing business decision some number of years ago (think "what happens if the IT system fails? how can we still ship stuff even in a complete emergency") and now it's baked into their documented process so deeply its like shouting into the wind to alter things. Third party warehouses are the worst at this.

Re:So you want to write your own CSV code (2014) by roto on Friday May 15, 2020 @07:34AM (#23190958)
Developers are by no means the only humans that use and/or edit CSV files.
Re:So you want to write your own CSV code (2014) by beaconstudios on Friday May 15, 2020 @07:33AM (#23190950)
Developers rarely use notepad. Non technical users still have to edit csvs by hand, all over the world.
Re:So you want to write your own CSV code (2014) by C1sc0cat on Friday May 15, 2020 @09:55AM (#23192191)
The average CSV use is as an export/import from excel and most of those users don't have specialised developer editors.
Re:So you want to write your own CSV code (2014) by kube-system on Friday May 15, 2020 @10:48AM (#23192795)
I have not seen very many business analysts open an IDE. In my experience, most edit CSVs in Excel.
Re:So you want to write your own CSV code (2014) by JauntyHatAngle on Friday May 15, 2020 @07:33AM (#23190952)
I don't think your first line is at all true.

Modifying Csvs with notepad is rife. I'd wager more than using any one particular code editor.

Re:So you want to write your own CSV code (2014) by arethuza on Friday May 15, 2020 @07:38AM (#23190989)
Or they use Excel, which can introduce its own entertaining errors.

A few years back while working on something that unavoidably used large quantities of CSV data we would sternly warn people not to use Excel, but people still did it ("But I just looked at it!").