Hacker News new | ask | show | jobs
by Nevermark 847 days ago
Common example of complications of two grammars being combined: C code and character strings.

Double quotes in C code mean begin and end of a string. But strings contain quotes too. And newlines. Etc.

So we got the cumbersome invention of escape codes, and so characters strings in source (itself a character string) are not literally the strings they represent.

1 comments

at no point in my life have I ever considered escape codes to be problematic.

ugly, yes. problematic? no.

Not problematic. Just a little cumbersome. (And ugly, agreed.)

You can't always just copy and paste some text into code, without adding escape encodings.

Now write code that generates C code with strings, that generates C code with strings, and ... (ahem!)

It's not a big deal, but it isn't zero friction either. Relevant here because it might be the most prevalent example of what happens when even two simple grammars collide.

until you need to get your string through several levels of escape. how many backslashes to add? depends on how deep your pipe is and how each of those layers is defined
The only alternative is extracting them to other files or designing specialized string formats.
There is one obvious "specialized string format" that solves 99% of all escaping issues: use «balanced quotes». The real problem isn't escaping, it is that the same character is used both to open and close strings.
Or old Fortran style Hollerith constants. They consist of the string length, a "H" and the string itself. Like 13HHello, world!
Qwerty has ` and ', but for some reason we've decided that '' isn't " and " is the one true quotation symbol.
Won't you still have to escape the closing bracket if it occurs inside the string?
Only if you want to refer to it literally as a closing quote rather than having it act as a closing quote. That case is extremely rare.
I also once had to pick up around the house and it was oh so terrible.
> problematic?

Unless it's a regex....