Live data from Hacker News

ASCII Delimited Text – Not CSV or TAB delimited text

ronaldduncan.wordpress.com

121–130 of 286 posts

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#121
post #36
post #10

I've done this. Everybody hated it. Most text editors don't display anything useful with these characters (either hiding them altogether or showing a useless "uknown" placeholder), and spreadhseet tools don't support the record separator (although they all let you provide a custom entry separator so the "unit" separator can work). Besides the obvious problem that there's no easy way to type the darned things when som…

Yes, but nowadays this is just another bootstrap problem: editors don't support them because no documents use them, no documents use them because editors don't support them, and users scream and bawl because their cheese has moved. Using an editor with some good support for control-character-separated data would be pleasant, more pleasant than the usual experience of fiddling with CSV in a text editor. That said, ano…

if the object is given a UUID, the recursive data structure can just point to the UUID when it's serialized to this? what's the problem?

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#122
post #66

Earlier quoted context omitted.

TLDR: it's superior, but don't do it...

It is strictly less expressive, because it can't handle nesting. This makes it inferior.

What would make one pair of ASCII characters (comma/linefeed or tab/linefeed) handle nesting any better than another pair (unit separator/record separator)?

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#123
post #94
post #84

Earlier quoted context omitted.

Even ignoring additional time needed to send those extra characters, it also was a lot faster than those control-H's, and (I guess) caused way less wear on your printer.

That presumes you're going like A^HAB^HB; you could just emit foo, and then strlen(foo) ^Hs.

I wonder how precise the backspacing was - how many times could you print a character and backspace before the head had drifted by a full point?

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#124
post #109

Earlier quoted context omitted.

I'm looking at my English keyboard and it has Alt Gr...

Qwerty keyboards intended specifically for the US market (opposed to the UK for instance) frequently do not have AltGr keys. The thinkpad I'm using right now doesn't have one, and the Das Professional I have next to me doesn't have it either. Come to think of it, I'm not sure if I've ever owned a keyboard with an AltGr key.. To get around this, I have taken to using xmodmap to turn my right alt key into altgr.

I'm surprised to learn that the Das doesn't have it.

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#125

Earlier quoted context omitted.

ASCII 0-31 are called "control" characters so it should come as no surprise that you could type them using the Control key. Unit Separator is Control-_ (underscore) and Record Separator is Control-^ (caret), for instance. Most modern text editors won't pass through every control character. Vim lets me type the unit separator, but not the record separator, for instance. Control-C and Control-D, End of Text and End of…

Vim will let you type the record separator, but you may have to precede it with Ctrl-V. In other words, type the Ctrl-V Ctrl-^ key sequence. At least, that worked for me. Interesting that the unit separator does not have the same requirement to precede it with Ctrl-V. More info in the vim docs: http://vimdoc.sourceforge.net/htmldoc/insert.html#ins-specia...

Yes, Ctrl-V in {insert,command} mode lets you input literal control characters, as well as numeric codes (31 for unit separator, 30 for record separator). If you're using vim on Windows, however, note that the default vimrc loads mswin.vim which changes Ctrl-V to paste. In that case, you can simply remove mswin.vim from your vimrc or use Ctrl-Q instead. (See :h i_Ctrl-V).

You can also use Ctrl-K to enter RFC1345 digraphs, in which case unit separator is 'Ctrl-K US' and record separator is 'Ctrl-K RS'. (See :h Ctrl-K).

Emacs has similar features, as well as a nifty TeX input mode: http://stackoverflow.com/q/6269618

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#126

CSV is a solved problem - RFC 4180: http://tools.ietf.org/html/rfc4180#section-2 As used by Lotus 1-2-3 and undoubtedly others before there was an Excel. Example record: 42,"Hello, world","""Quotes,"" he said.","new line",x Now go write a little state machine to parse it... (hint: track odd/even quotes, for starters)

Coincidentally I did this just this week. I believe there's no need to track quotes, just if it has an opening quote or not. That RFC really explains it all very well. The only edge case I had was with empty records (foo,,bar) and that was probably due to my implementation.

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#127
post #57

Don't do this. Tsv has won this race, closely followed by Csv. Anything else will cause untold grief for you and fellow data scientists and programmers. I say this as someone who routinely parses 20gb text files, mostly Tsv's and occasionally Csv's for a living. The solution you are proposing is definitely superior but isn't going to get adopted soon.

I was surprised to see you list tsv as more common than csv. I encounter csv's on a pretty regular basis, but I don't think I've had to parse a tsv in the past 3 or 4 years. As a junior web developer, I don't have much experience though. 9 times out of 10, the csv is coming from or going to Excel, or a system that was designed to support Excel. If you don't mind my asking, what types of data do you regularly work with that are in tsv format?

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#128
post #111
post #92

Earlier quoted context omitted.

You know what's nicer than delimiting beginnings and ends of things? Length prefixing. Protocol message formats and data encoding formats both already know what they're going to say before they say it, and so know its octet length. The only reason to use delimiters, ever, is for user-modifiable data (e.g. source code) where you might want to insert or delete characters and have the containing block remain valid. ---…

The problem: I have never encountered length-prefixed data. Ever. Every data interchange file I've ever dealt with has been either delimited or fixed-width fields (and the widths are not defined anywhere in the file).

Examples of length-prefixed data abound in protocols and formats defined by systems and telecom engineers (e.g. the IETF). IP packets are length-prefixed. ELF-binary tables and sections are length-prefixed. PNG chunks are length-prefixed.

It's just these worse-is-better text-based protocols like HTTP, created by application developers, that toss all the advantages of length-prefixing away. (And, even then, HTTP bodies are length-prefixed, with the Content-Length header. It's just the headers that aren't.)

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#129
post #79

Earlier quoted context omitted.

...and that's why, when running a command that's reading what you're typing to stdin, you press Ctrl-D to tell it that you're done. Because, as your "man ascii" trick shows, this generates the "end of transmission" character. Similarly, Ctrl-L clears the screen in most Unix apps because that generates the "form feed" character, and on a line printer or paper-based teletype terminal, "form feed" means to advance to th…

what about Ctrl-C to break out of stuff? Does that correspond to an ascii control character?

I was disappointed that Ctrl-S and Ctrl-Q don't correspond (at least on the first ASCII chart I googled) to anything, because Ctrl-S stops text on my Unix terminals the exact same way it did on my brother's Apple ][e in 1984.

Re: ASCII Delimited Text – Not CSV or TAB delimited text

#130
CSV if you do it as in RFC 4180 [1] already has everything the link describes, plus pretty good interoperability with most things out there. If you abused CSV you could even store binary data, while ASCII has no standard way to escape the delimiter characters.

1: http://tools.ietf.org/html/rfc4180

Post reply on HN