Hacker News new | ask | show | jobs
by andix 1725 days ago
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...
3 comments

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