Multiline string literals: can we get rid of the need for stripMargin?

That’s fine. I have no strong preferences for syntax here. I just want the functionality.

The problem is: There are not much options…

I actually even proposed a very “ugly” syntax first, which uses the trick C# uses. You would have than a whole row of """""""" in some cases. Ugly but functional.

The syntax needs to be short I think, it needs to make it clear that a String literal starts, and it needs to be unambiguous. The proposed string: is not, also not in combination with interpolation (because that’s an infix call to a function taking a closure).

I actually think it would even work with a single "\n but that would only make more chaos with :.

No matter the concrete syntax, I think it needs to be a “only opening” symbol anyway. Because the whole point is to not need a closing symbol and just use indentation.

But inventing a third, distinct syntactic option to declare string blocks seems quite odd. Martin said the same actually.

Like said, the design space is anyway quite limited. You have basically two options:

Something that resembles “here document” (here-doc symbol followed by custom delimiter, which needs to be repeated at the end), or using indentation as delimiter (with unindent as closing symbol).

After agreeing on the variant the only thing that can be discussed is actually which symbol opens the text block. But if you don’t want to add new syntax only for this use case (which is bad) there are not much options either. It’s " or """.

And using the here document variant (which is more or less also what C# does) ignores having indentation based blocks in the language, which is inconsequential. Still the algo for indented blocks needs to be applied to these text blocks to get rid of stripMargin… The ending symbol is than just redundant noise that has no technical reason for existence.

All the examples so far introduce a val, for which one can already use an optional end marker, e.g., end myJson. As a user, I certainly would not want another (required) end marker to finish the string.

1 Like

I certainly would want an end marker, because in multiline strings where whitespace matters, I need to be able to specify how much whitespace to include at the end.

Using block scope seems very unreliable for that.

2 Likes

How many syntax highlighters do you think will support this?

1 Like

I’d rather not have another way of defining a string and don’t mind the | and .stripMargin: in fact I’d say it helps me see where the margin is, rather than have me count whitespaces and hope it ends up where it should.

3 Likes

The term “gutter” means the extra margin at the bound edge of pages in a book.

We may adapt that definition to any margin adjustment according to a context, such as the margin of an embedded multiline literal.

So if anyone manages to nerdsnipe a contributor into implementing this feature, that would be a guttersnipe.

(Internet says guttersnipe was “Wall St slang for streetcorner broker” but that seems less likely than the general sense. But “snipe” was a “term of opprobrium” since Shakespeare.)

Edit: this feature would have helped a test failure where “trailing incidental white space” in a “text block” was helpfully deleted by the text editor. Suddenly, it’s a feature one can’t live without. I think someone asked for \s as well.