5 ms·
The fact that ASCII does not have balanced quotes is one of the great catastrophes of computing. It makes everything more complicated than it needs to be, from
by lisper 9y ago
The fact that ASCII does not have balanced quotes is one of the great catastrophes of computing. It makes everything more complicated than it needs to be, from embedding code in strings to parsing CSV files, to regexps. For example, if I want to embed a quoted string in another quoted string, I have to escape the inner quotes like so:
"This is string containing an embedded \"quoted\" string"
Then I have to think about whether or not the system I'm going to send that string to is going to "helpfully" remove the backslashes, in which case I need to write:
"This is a string containing an embedded \\"quoted\\" string"
God help you if you want to go two levels deep.
All this horrible complexity could have been avoided if we could just write:
«This is a string containing an «embedded» quoted string»
Alas.
- agumonkey 9y agolet's rewrite social idioms to use < > as quotes.
- Symbiote 9y ago«These characters» are the usual way of quoting in several languages. See https://en.wikipedia.org/wiki/Guillemet https://en.wikipedia.org/wiki/Guillemet
- Pxtl 9y agoWell then it's a good thing c used its ASCII equivalent that's accessible on anglophone keyboards for bit shifting and so if any programming language tried to use <<strings>> you'd have c grognards screaming about lshift and rshift.
- eesmith 9y agoThe complexity might be minimized, but not avoided. You would still need an escape mechanism for something like «She said «The \» key on the server doesn't work.»» ASCII did add <>, [], and {}, any of which could have been used for quoted strings, had the programming language designers chosen that option. https://en.wikipedia.org/wiki/String_literal#Paired_delimiters https://en.wikipedia.org/wiki/String_literal#Paired_delimite... points out that PostScript and Tcl have a string literal which allows matched quotes. PostScript: (The quick (brown fox)) Tcl: {The quick {brown fox}}
- lisper 9y ago> You would still need an escape mechanism for something like... Yes, but that's a pretty rare case, much more so than embedded strings. Even that case could be solved by having two different quotes, like Python which allows both 'string' and "string". So you could do: «This is a string that mentions the ” character without escaping it» “This is a string that mentions the « character without escaping it” Yes, there are still some edge cases, like embedding both “ and « in the same string. But that's really rare.
- PickNChoose 9y agoYou don't want any 'rare' cases at all. That's the point. Stop using "punctuation" when you are attempting to "delimit" text. Use a character that is not punctuation, specifically designed for "field delimiter" purposes. Trying to do two things at once is ridiculous.
- diamondo25 9y agoI've been trying to push TSV (tab separated values) as a standard response/implementation when they ask for CSV. "Yes but its comma separated!", sure is, but text can contain commas... I have seen issues with Google Spreadsheets not recognizing the tabs however... Excel doesnt know what to do with a TSV either. But both have a complete wizard for parsing CSV...
- emmelaich 9y agoIf it's for my own programs, I use pipe (|) separated values. They're visually appropriate and even less likely than tabs.
- spc476 9y agoASCII does contain control characters set aside for record and unit separators (codes 30 and 31 respectively). Sometimes I wish they got more use than they do.
- tome 9y agoIf ASCII had balanced quotes then they would be used by programming languages to delimit strings and we would be back to square one with regards to escaping them!
- hk__2 9y agoYou don’t need escaping in «This is a string containing an «embedded» quoted string».
- drdeca 9y agoI think it would make the parsing a tiny bit more inconvenient though
- Pxtl 9y agoYup, suddenly your parser needs to keep a count of how many nested strings deep it is.
- jrochkind1 9y agoruby does that. computers are pretty fast now.
- userbinator 9y agoDon't forget that "parser" also includes human brains, which tend to not be that great at parsing nested things. To use formal language theory, strings containing escape characters are regular, i.e. parseable with a finite-state machine. Allowing nesting means you need a stack to find the matching pair.
- munificent 9y agoIt's not hard. Obviously the parser has to do that things that aren't a single token like parenthesized expressions. Even for things where the nesting does happen during lexical analysis, it's pretty trivial to keep a count in your lexer. Lots of languages support nesting comment syntax or string interpolation, which both have equivalent difficulty.
- vvanders 9y agoYeah, seen a ton of tools that auto-format to left/right quote automatically but then output ASCII and mangle the conversion.
- zaxomi 9y agoActually, ASCII have mechanism for solving the problem that you describe, with control codes FS, GS, RS and US.
- coldtea 9y ago>All this horrible complexity could have been avoided if we could just write Only if there was no chance of unbalanced quotes to need to be in the string.
- mort96 9y agoYou'd still have escape sequences for those cases.
- deleted 9y ago[deleted]
- cgtyoder 9y ago> The fact that ASCII does not have balanced quotes is one of the great catastrophes of computing. Okay.
- jiggunjer 9y agoI disagree. Sure it might regex better, but my typing speed and typo rate would be much worse if I had to type separate open and close quotes for all my strings.