The state of string interpolation
Andre Pany
andre at s-e-a-p.de
Thu Dec 6 17:47:58 UTC 2018
On Thursday, 6 December 2018 at 16:19:12 UTC, Steven
Schveighoffer wrote:
> On 12/6/18 4:01 AM, Dennis wrote:
>> [...]
>
> I supported the concept[1] back when I read it from Dmitry
> Olshansky[2].
>
> If I had known about the debate on the PR I would have jumped
> in. But I don't have much to add. All that really dictates my
> views is the experience I've had with other languages. However,
> none of those other languages have the same concept that I know
> of -- they basically just create a string with toString-ing the
> interpolations.
>
> With the concept of lowering to a tuple, I'd love to use such a
> thing for database queries.
>
> For instance:
>
> db.exec("UPDATE Foo SET a = ?, b = ?, c = ?, d = ? WHERE id =
> ?", aval, bval, cval, dval, id);
>
> vs.
>
> db.exec(i"UPDATE Foo SET a = $aval, b = $bval, c = $cval, d =
> $dval WHERE id = $id");
>
> The mixin/library solution is much less approachable. What's
> awesome about the language solution is that it just works
> without much extra understanding and verbosity, and need for
> using mixins. mixins are cool, but are best tucked away behind
> templates or generative functions. They shouldn't seen much in
> user code. Saying we should use a library solution for this is
> like saying we can replace foreach usage with a library foreach
> that lowers to some for-loop and explicit delegates (or maybe a
> mixin?). Yes, it could be done. No, it shouldn't be done. This
> is one of those types of syntax sugar that should not be
> ignored.
>
> +1000 from me, I'd love to see the PR merged, or the DIP
> created, whatever needs to happen.
>
> -Steve
>
> [1] https://forum.dlang.org/post/odb9hk$2jqm$1@digitalmars.com
> [2] https://forum.dlang.org/post/ocut06$261n$1@digitalmars.com
Does I understand your sql example right, although it looks like
it is prone for sql injection attacks, it isn't because you
evaluate the tuples and not use the string as whole?
I really like this feature. Everytime I have to concatenate
strings and variables I really really miss this feature.
I would propose Mike starts a donation campaign for this DIP.
Then op and others can donate in an official way.
Kind regards
Andre
More information about the Digitalmars-d
mailing list