DIP 1027--String Interpolation--Final Review Discussion Thread
FeepingCreature
feepingcreature at gmail.com
Wed Feb 5 05:48:45 UTC 2020
On Wednesday, 5 February 2020 at 05:26:30 UTC, Walter Bright
wrote:
> The reason for formatted strings is for formatting that is
> other than the default, and to interface with common functions
> that use formatted strings.
>
> Strings and expressions are stuck with the default format. If
> you're happy with the default formatting,
>
> writefln("I want $i bananas");
>
> is not much of any improvement over:
>
> writeln("I want ",i," bananas");
I think it's still a significant improvement. In my experience,
anything that forces you to context switch from "inside string"
to "outside string" is a frustrating source of typos and 'mental
hiccups'. The point of format strings is that you can "stay
inside" the string context and open a *new* expression context
instead of mentally pre-flattening the string tree out into a
list of fragments. (This is also a significant weakness of mixin
strings.)
In other words, the difference between ("I want $i bananas") and
("I want ", i, " bananas") is that one is (I want (i) bananas)
and the other is ((I want ), (i), ( bananas)) - going down to
nest vs going *up* to nest.
This may sound trivial, but trivial syntax enhancements matter,
especially for a "top-ten" feature like format strings.
More information about the Digitalmars-d
mailing list