What's the point? I cringe every time a project uses both double quote and single quote, a mix of semicolon and no semicolon and a mix of tabs and space, .... Which one to pick isn't relevant as soon as the code base is consistent
What's the point? I cringe every time a project uses both double quote and single quote, a mix of semicolon and no semicolon and a mix of tabs and space, .... Which one to pick isn't relevant as soon as the code base is consistent
E.g., how would you put the following sentence in a string:
You can use both " and ' to delimit a string.
"You can use both \" and ' to delimit a string"
The benefit of JSON is that it's simple, opinionated, and pretty. Putting bells and whistles on it ruins the very ethos of JSON. If you want JSON++, use XML or Jsonnet or whatever.
The 99% case is a pretty string. The 1% case is a string with escaped delimiters.
The most practical solution for this problem I saw was in F#. You can use tripple-quoted strings.
let a = """The diner is called "John's", but you can't let the string end with a double quote"""
https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe... "normal string can contain ' "
r#" raw string can contain " ' "#
r###" if for some reason you need to write "# "###
Kinda like heredocs const hello_world_in_c =
\\#include <stdio.h>
\\
\\int main(int argc, char **argv) {
\\ printf("hello world\n");
\\ return 0;
\\}
;
It neatly sidesteps the whole "cat-and-mouse" issue.Pair this with the fact that it only has the C++ style // comments, it means that every line can be tokenized independently. Not that that particularly matters for programmers, but I know Vim sometimes gets confused about where Python's strings end and it turns the syntax highlighting to garbage.
// the object key here is "weird object key '\""
{%{weird object key '":}%:"see how it works?"}
// ditto
{%""{weird object key '":}""%:"see how it works?"}According to this Stack Exchange answer[0], the backtick is strictly for use in computing. I understand that it represents the grave accent, but that isn't of concern as a string delimiter, because once it is applied to a letter, for example è, it has its own unique representation.
0: https://english.stackexchange.com/questions/249406/are-backt...
Or they could pull a YAML, and retroactively redefine what JSON stands for, the way YAML originally stood for "Yet Another Markup Language" until some party pooper pointed out to their great surprise that YAML was not actually a document markup language, but a data serialization language, so they redefined it to mean "YAML Ain't Markup Language" -- the opposite of what it originally meant.
https://en.wikipedia.org/wiki/YAML#History_and_name
https://en.wikipedia.org/wiki/Markup_language
Pro Tip: When naming you file format, look up what the words in your acronym mean, first.
Some code bases use single quotes, and it's annoying to copy/paste an object from that code into a JSON objdct and have to change the quotes.