Hacker News new | ask | show | jobs
by itsibitzi 1725 days ago
It allows you to put double quotes in the string without escaping them, which is pretty nice.
3 comments

But then you can't include single quotes into the string any more. Same problem again.

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...
Rust has similar but it scales infinitely. They're called raw strings,

  "normal string can contain ' "
  r#" raw string can contain " ' "#
  r###" if for some reason you need to write "#  "###
Kinda like heredocs
Most (newer) programming languages have a concept of multi-line string literals.
My favourite variation is from Zig:

    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.

it also fixes the indentation problem
Most newer languages only have 1 variation, not infinite. Go only has backtick, python only has triple quotes. Rust has #", ##", ###", ##...#"
I would prefer PostgreSQL-style arbitrary quotes, but with nesting. Something like:

  // the object key here is "weird object key '\""
  {%{weird object key '":}%:"see how it works?"}
  
  // ditto
  {%""{weird object key '":}""%:"see how it works?"}
This is why I like backticks. ` should almost never show up in normal English text.
And, luckily, all transmitted text is normal English.
I'd be interested to see a counter example where a standalone backtick is part of normal non-computing related text. I really don't find your comment helpful. The strings where I see single and double quotes being used most frequently is with normal, yes, English text. The backtick is useful there, and that's all I wanted to say. French doesn't really have the same issue, since guillemets (« and ») are often used in place of double quotes, for example.

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...

I think the point was that it doesn't make sense to expect that strings in a format like JSON or a programming language will only be used for non-computing related plain text.
If English was good enough for Jesus Christ it's good enough for me
An annoying half-solution that breaks down as soon as you encounter content with both. Better imho to have one way and become good at it. I think I might even prefer trailing commas to be mandatory.
It solves the problem like 99% of the time in my experience. It's very rare that I have content with both single and double quotes.
That's exactly my point: 99% solutions are the worst. Every 99% solution will eventually find someone relying on it, willingly or not. And it's always someone else cleaning up the mess (or failing to find the cause).
There is no mess.

The 99% case is a pretty string. The 1% case is a string with escaped delimiters.

Why does it need commas at all? What purpose do they serve?
They don’t serve one. Clojure uses only white space for distinguishing items in lists and hashmaps and after a short period of “this is weird” you embrace it and wonder why you ever needed commas at all
Checksums, basically, drawing a line between random bytes and structured JSON in a way that comes at zero cost for a human mind (arguably less than zero). We might as well leave out all closing tokens at the end of the stream, in a way those are completely redundant but still worth it for the warm, fuzzy feeling of knowing that you haven't just read a truncated stream.
It's either commas or significant whitespace. No matter what you'll find someone who hates one or the other.
But everyone puts the whitespace in anyway so why not just make it significant?
What if you want both?

E.g., how would you put the following sentence in a string:

You can use both " and ' to delimit a string.

You'd use escapes:

"You can use both \" and ' to delimit a string"

That was their point, you inevitably have to escape one or the other, so just pick one
My only disagreement is that you imply that this is no better than plain old JSON – I think it's positively _worse_. It makes it difficult to remember which of the two quote marks to escape, without checking the beginning of the string to see what quote marks were there (and this difficulty exists not only for humans but for machines, which introduces more complexity in parsers).

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.

I didn't imply that, in fact my comment agrees with what you are saying. Did you reply to the wrong person?
Haha, I only meant that as a "I agree with you, but I'd go even further" preface. In hindsight, this being HN, I should have been more precise!