The state of string interpolation
Jonathan Marler
johnnymarler at gmail.com
Fri Dec 7 18:05:04 UTC 2018
On Friday, 7 December 2018 at 17:11:35 UTC, Atila Neves wrote:
> The only use I'd have for string interpolation is when
> generating code (as a string) that spans multiple lines. Before
> this thread I wasn't aware that scriptlike had string
> interpolation. Now that I know it does, I don't know what I'd
> need "proper" (i.e. language assisted) SI.
>
> Every language change is a cost, and therefore should justify
> its inclusion. I personally don't think that it is in this case
> just to make a niche use case slightly easier, and this coming
> from someone from that niche! From now on it's:
>
> const code = mixin(interp!q{
> // stuff that I used to write with many %s and it was hard
> to match them up
> });
Your reasoning is sound but we differ in opinion here. In my
opinion the cost is low. The implementation is very isolated.
It's a simple change to the lexer and a new function call in
parse stage that returns a tuple, that's it. You also say the
usefullness is "niche" but I would disagree. If it's implemented
in the language then it could potentially replace the majority of
calls to writeln/writefln. It's more efficient than writefln and
easier to read/maintain than writeln. You yourself made a
mistake in your own example because writeln is so clumsy to use.
That's how I would use it anyway, I can't speak for everyone else
but I think many people see this benefit as well.
More information about the Digitalmars-d
mailing list