3 ms·
The Raku language (https://raku.org https://raku.org) nails multiline strings and avoids the triple quotes issues mentioned in the OP. say q:to/END/; Her
by librasteve 1y ago
The Raku language (https://raku.org https://raku.org) nails multiline strings and avoids the triple quotes issues mentioned in the OP.
say q:to/END/;
Here is
some multi line
string
END
https://docs.raku.org/syntax/heredocs%20%3Ato https://docs.raku.org/syntax/heredocs%20%3Ato
- IshKebab 1y agoThat's probably the worst multiline string option if you ask me. Looks like they copied Bash.
- librasteve 1y agoYes, the evolution of Raku multilines is from shell (heredoc) > perl > raku, and a LOT of experience went into the design. Not sure I understand why that's a bad thing? Some benefits of the Raku solution are: - multiline is just a superset of the standard quoting method (with the "to:/CLOSER/" adverb) - indent level is set by the left edge of the closer, in the example 'END' ... so you can consistently indent / unindent your source and do not have to crowd all your heredoc to the left margin - you can pick any delimiter or closer to avoid conflict with the text content - there's a large selection of quoting adverbs - q (like single quotes), qq (like double quotes), qw (quote word), qx (shell quoting), etc. This usually means that any text can be cut and pasted as is into the multiline and you can adjust the adverbs to match the original quoting pattern. Even with perverse patterns (which you cannot guarantee against in variable text), there is a way to gracefully handle: q«say '''hi"""» #say '''hi""" https://docs.raku.org/language/quoting https://docs.raku.org/language/quoting
- afiori 1y agoThe best multiline strings are those where you can have proper indentations without having to guess how indentation is handled. bonus points for making nesting easy and making copy-pasting work without breaking indentation. To my knowledge only Zig's multiline strings work this way const hello_world_in_c = \\#include <stdio.h> \\ \\int main(int argc, char **argv) { \\ printf("hello world\n"); \\ return 0; \\} ;
- librasteve 1y agookaay, I get that you want the indentation to work (ironically this is more important when you are multilining a Python code example), but having to manage all the \\ is a pain in the butt
- oneeyedpigeon 1y ago> ironically this is more important when you are multilining a Python code example And neither seems to be a great use case for configuration. A markup language, sure, but I'm not sure I see a significant need for multiline strings (even in general) in a config file.
- librasteve 1y agofair point … although I can see a use case for eg multline multi languages contractual boilerplate that i don’t want in my main code
- afiori 1y agowith multiple cursors its easier than any alternatives
- 1718627440 1y agoIn C: char string[] = "multi\n" "line\n" "string"; Granted, this is not a real multiline string, but you also have characters in your Zig example that are not part of string content (\\).
- pavel_lishin 1y agoI clicked on that FAQ link, because I wasn't familiar with zig-style multilines, and my initial reaction was "ew, ugly" - but reading the justifications, I think it rather won me over with how it addresses the indentation issue alone.
- afiori 1y agosuper ugly but they work just like inline comments and so are super easy to use/nest/visually detect and such. for example in css which does not have inline comments vscode fails to reliably comment a block of text. for strings it is even worse as usually they use the same tokens for opening and closing which make everything more ambiguos