Follow

Many programming languages have syntax that means "everything from this token until the end of the line is a comment" (e.g., // in C-family, ; in Lisp family, # in shell family)

Do any have syntax for "everything from this token until the end of the line is a string"?

Why isn't that a common thing to have? It strikes me as something that'd be *super* handy

@codesections why would that be super handy? I don’t see a use case

@SonoMichele

> why would [a string that runs until the next newline] be super handy? I don’t see a use case

Basically to avoid needing to escape anything. Here's some pseudo-js with # as the string-until-end-of-line character

return # He's a really good
+# guy, but I still said,
+# "Don't even go there!"

@codesections makes sense. In python you can do

return “my ” \

“String” \

Although it isn’t the same thing but I think it works well

@codesections some languages let you have newlines in a string literal, that covers the need quite well imo

@codesections There are ones which say "everything from this token until the end of line is output", or maybe it's the lack of some token. SQLite's "Fossil" version control system wrote their own preprocessor to add this to C...

@fedops

> here-documents in the sh family.

Sort of, but not really. That's actually what got me thinking about this: a heredoc like

cat << EOF
"He's a zany fellow!"
EOF

takes 3 lines, which is a lot of verbosity for a one-line string. And I started thinking "shame I can't just have a newline as the delimiter", which led to the OP.

(Well, except that I was writing , not shell, so the heredoc I was using has some superpowers, docs.raku.org/language/quoting But it still needs a delimiter!)

@codesections well you could use the here string with <<<. It can be on the same line and then works until its end. E.g.:
dc <<< 2 2 + p

@codesections S" in Forth ends up working like that, but as usual in Forth, syntax isn't really the right word.

@codesections My guess is that a lot of languages require a statement terminator. In C that would mean either the end of line implies a terminator or the terminator goes on the next line. Those are both gross, extra gross because the ; is a separator not a terminator.

Not all languages, of course. But usually these language features are copied from someone else.

@tewha

> Not all languages, of course. But usually these language features are copied from someone else.

Yeah, I bet that's it. Come on, language designers, show some creativity!

@codesections Spoken like a Perl/Raku programmer 😂 Personally I think the level of creativity in string syntax is too damn high. Single quotes, double quotes, triple quotes, escapes, % interpolation, {} interpolation, f-strings, L-strings, u8-strings, R-strings.. did I miss any?

Comments extend to end of line, but in many languages that's all you get. I'd support a language where strings extend to end of line, and that's all you get.

@tewha

@codesections Some languages have a triple quote """ or backtick token that denotes strings that don't need escaping. E.g. Kotlin kotlinlang.org/docs/coding-con
or Scala alvinalexander.com/scala/how-t

Very useful for regular expressions.

Not quite what you are looking for though

@codesections Or just use Scheme (LISP, too?) where strings only terminate at the next ", no matter how many newlines are inside.

Python & some others have """ or ''' for block strings.

JavaScript now has ` strings, which do interpolation of $() vars, and are multiline until the ` terminator. Great for templating HTML, about 20 years after everyone got their templating systems just right.

@codesections intetesting idea, perhaps looking at the history will clarify why that is. My guess would be that "until the end of the line" comments facilitate easy multi-line commenting often seen at the top of files. Why not the inverse: why do so few languages allow for middle-of-a-line comment?

@mcol

> Why not the inverse: why do so few languages allow for middle-of-a-line comment?

I mean, not _that_ few: most C-family languages have
/* comments */, which work fine for middle-of-the-line comments (even if they're often called multiline comments)

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.