5 ms·
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 us
by andix 5y 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-reference/strings#triple-quoted-strings https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
- conradludgate 5y agoRust 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
- 0xdeadb00f 5y agoMost (newer) programming languages have a concept of multi-line string literals.
- conradludgate 5y agoMost newer languages only have 1 variation, not infinite. Go only has backtick, python only has triple quotes. Rust has #", ##", ###", ##...#"
- Rendello 5y agoMy 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.
- afiori 5y agoit also fixes the indentation problem
- deleted 5y ago[deleted]
- cryptonector 5y agoI 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?"}
- jagger27 5y agoThis is why I like backticks. ` should almost never show up in normal English text.
- skowron 5y agoAnd, luckily, all transmitted text is normal English.
- jagger27 5y agoI'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-backticks-used-outside-of-computing https://english.stackexchange.com/questions/249406/are-backt...
- kapep 5y agoI 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.
- keithalewis 5y agoIf English was good enough for Jesus Christ it's good enough for me