5 ms·
I greatly prefer TSV over CSV. https://en.wikipedia.org/wiki/Tab-separated_values https://en.wikipedia.org/wiki/Tab-separated_values
by nayuki 2y ago
I greatly prefer TSV over CSV. https://en.wikipedia.org/wiki/Tab-separated_values https://en.wikipedia.org/wiki/Tab-separated_values
- recursive 2y agoThanks for your input.
- adzm 2y agoAgreed, much easier to work with, especially if you can guarantee no embedded tabs or newlines. Otherwise you end up with backslash escaping, but that's still usually easier than quotes.
- recursive 2y agoIt's not really easier than CSV if you can guarantee no commas or newlines.
- jefftk 2y agoMuch easier to require fields not have tabs than not have commas, though.
- solidsnack9000 2y agoParsing escapes is easier than parsing quoted text with field and record separators embedded in it. Every literal newline or literal tab is a separator. One can jump to the thousandth record, for example, just by skipping lines, without looking into the contents.
- alkh 2y agoThe problem with using TSV is different user configuration. For ex. if I use vim then Tab might indeed be a '\t' character but in TextEdit on Mac it might be something different, so editing the file in different programs can yield different formatting. While ',' is a universal char present on all keyboards and formatted in a single way
- tgtweak 2y agoCsv suffers from similar encoding and platform specific gotchas surrounding newlines and delimiter escaping.
- caspper69 2y agoWell, back in my day, we used tabs for tabs. But then some folks came along about 15 years ago screaming about spaces, and they won, so now tabs are 2 or 4 spaces. The law of unintended consequences strikes again! Note: not meant to denigrate you space supporters out there.
- marcellus23 2y agoThe only situation I can think of where a tab is not a tab, is in a code editor that's been configured (possibly by default) to use spaces instead. But that's an easy enough configuration to change. And certainly wouldn't be a problem for something like TextEdit.
- Night_Thastus 2y agoFunctionally the same. I'd prefer CSV if my content was likely to have whitespace in it and didn't want billion quotes. I'd prefer TSV if my content was unlikely to have whitespace, and more likely to contain commas.
- bee_rider 2y agoCSV is a pseudo-standard anyway, IMO the delimiter should be a configurable option (like it is in Unix cut and those kinds of tools).
- Suppafly 2y ago> IMO the delimiter should be a configurable option It is. CSV has been character separated vs comma separated for probably decades now. Most tools you'd use to mess with them allow you to specify which separator character is being used.
- bee_rider 2y agoI agree although it seems to render the distinction made by GP moot, right?
- mort96 2y agoTSV looks incredibly ugly when opened in a text editor unless all values are 7 characters or less.
- ciupicri 2y agoSet a bigger tab size in the editor, e.g. `:set ts=32` in vim.
- mort96 2y agoAaaand now I can fit like 3 fields next to each other before they wrap and the field with arbitrary length text still misaligns the field after it
- bee_rider 2y agoThere is at least a chance that the text fields will fit in a tab. If not, a tool like “column” on Linux can be used. There is no chance that a text field will fit inside the width of a comma.
- ciupicri 2y agoI was about to mention that column [1] is part of util-linux, so perhaps it's Linux specific, but then I noticed this in the FreeBSD man page [2]: > The column command appeared in 4.3BSD-Reno. [1]: https://man7.org/linux/man-pages/man1/column.1.html https://man7.org/linux/man-pages/man1/column.1.html [2]: https://man.freebsd.org/cgi/man.cgi?query=column&sektion=1 https://man.freebsd.org/cgi/man.cgi?query=column&sektion=1
- cgb_ 2y agovartabstop can help with per-column width. I found https://sharats.me/posts/automating-the-vim-workplace-3/#using-vartabstop-to-line-up https://sharats.me/posts/automating-the-vim-workplace-3/#usi... which greatly improved my TSV editing experience in vim. Couple that with autocmd TextChangedI and you get realtime recalculation and alignment.
- 2y ago
- putlake 2y ago100% agree. TSV is under-rated. Tabs don't naturally occur in data nearly as often as commas so tabs are a great delimiter. Copy paste into Excel also works much better with tabs. Code editors may convert tabs to spaces but are you really editing and saving TSV data files in your code editor?
- ciupicri 2y agoThe problem with TSV is what are you going to do about quotes. Some fields might contain them [1] or they might be needed to store fields with tabs inside them. Because of this in order to read a plain simple TSV (fields separated by tabs, nothing more) with the Python csv module [2] you need to set the quote character to an improbable value, say € (using the euro sign because HN won't let me use U+1F40D), or just parse it by hand, e.g. row.split('\t'). [1]: https://github.com/wireservice/csvkit/issues/1194 https://github.com/wireservice/csvkit/issues/1194 [2]: https://docs.python.org/3/library/csv.html https://docs.python.org/3/library/csv.html
- makeworld 2y agoQuotes are just characters in TSV. Actual tab characters are banned so this should be simple. (Of course poor implementations may behave differently.)
- solidsnack9000 2y agoTSV's big advantage is that, as commonly implemented, the separators are escaped, not quoted. This means that a literal newline (ASCII 0x0A) is always a record separator and a literal tab (ASCII 0x09) is always a field separator. This is the format many databases -- including Postgres -- use for text export by default. There are some notes I put together about TSV a few years ago that expand on these points: https://github.com/solidsnack/tsv?tab=readme-ov-file#motivation https://github.com/solidsnack/tsv?tab=readme-ov-file#motivat...
- anthk 2y agoUnix and AWK will parse it on the spot.