The state of string interpolation
Paul Backus
snarwin at gmail.com
Thu Dec 6 20:40:02 UTC 2018
On Thursday, 6 December 2018 at 19:39:17 UTC, Adam D. Ruppe wrote:
> On Thursday, 6 December 2018 at 19:12:52 UTC, Paul Backus wrote:
>> If users want to opt in to that extra complexity, it can
>> always be made available as a library.
>
> Well, maybe, but libraries can't get the info if it isn't there.
I'm not convinced that libraries *should* have access to that
info. Can you imagine having to debug a function that works when
you call it as `fun(i"foo$(bar)")`, but fails when you call it as
`fun("foo", bar)`? Sure, you can tell people not to write code
like that, but if you're going to take that position, why go out
of your way to make it possible in the first place?
>> The actual solution here is to use the type system to
>> distinguish between trusted and untrusted strings. E.g.,
>
> If you do that, then you really must forbid any plain string to
> force the programmer to declare it...
Sure, there are ways to make it even safer. My point is just that
this isn't a string interpolation problem, it's a problem of
conflating two different kinds of data just because they happen
to have the same representation.
More information about the Digitalmars-d
mailing list