Hacker News new | ask | show | jobs
by 0xdeadb00f 1725 days ago
Most (newer) programming languages have a concept of multi-line string literals.
2 comments

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 #", ##", ###", ##...#"