The state of string interpolation
o
o at o.o
Thu Dec 6 23:10:48 UTC 2018
On Thursday, 6 December 2018 at 22:52:28 UTC, Dennis wrote:
> On Thursday, 6 December 2018 at 22:34:14 UTC, o wrote:
>> Just think how much nicer this is (lowering to a string):
>> `foo(i"My name is $name");`
>>
>> Compared to this (lowering to a tuple, requiring a conversion
>> to a string):
>> ```
>> import std.conv: text;
>> foo(text(i"My name is $name"));
>> ```
>
> With UFCS it looks a lot nicer already:
> ```
> foo(i"My name is $name".text);
> ```
> How often do you actually need to pass an interpolated string
> to a function in string form? That's not a rethorical question,
> it is important to consider. If 90% of string interpolation
> happens in writeln / logging then it's not worth forcing the
> use of phobos + GC + eager toString and concatenation just to
> make the remaining 10% of cases a bit easier.
"forcing the use of phobos" does not only apply to
lower-to-string interpolation. Tuple and 'text()' functionality
all comes from phobos in the first place.
> If 90% of string interpolation happens in writeln / logging
> then it's not worth forcing the use of phobos + GC + eager
> toString and concatenation just to make the remaining 10% of
> cases a bit easier.
So lets say that tuple-interpolation covers 90% of the use cases.
What about the other 10%? If we used 2 different string prefixes,
ie `i"..."` for lower-to-string interpolation and `t"..."` for
lower-to-tuple, then 100% of the use cases are covered and
everyone is happy.
More information about the Digitalmars-d
mailing list