DIP 1027--String Interpolation--Final Review Feedback Thread

Adam D. Ruppe destructionator at gmail.com
Mon Feb 3 03:06:22 UTC 2020


> Mixing Conventional Format Arguments With Interpolated Strings

This DIP proposes leaving all % unmodified in the string, yet it 
also injects % characters into the string. This is a mistake - it 
forces user code to be aware of implementation details and 
carefully encode all special characters. Web programmers learned 
the hard way the problems of sloppy encoding.

As it stands, consuming functions have no way to tell if the 
first %s from `i"%s $foo"` is meant to go with the subsequent 
argument `foo` or the latter; it will throw off all future 
processing.

The DIP must be amended to specify that ALL % characters in the 
i"" string are replaced with %% in the yielded string.

> W and D Interpolated Strings

should work, the DIP rationale is poor. This is an arbitrary 
limitation and inconsistency with the rest of the language.

> [not present]

The DIP fails to address the feedback from the previous review 
round on concerns for overloading functions to use the new 
feature.

I move that we amend it so the format string literal is not 
created directly, but instead wrap it in  
`_d_interpolated_string!"..."` instantiation.

So

writefln(i"foo % $bar")

is rewritten to

writefln(_d_interpolated_string!"foo %% %s", bar);

This allows a library implementation to detect it for the 
purposes of function overloading with zero other loss relative to 
the DIP status quo (in fact, the template there could be defined 
to reduce to the literal exactly via an eponymous enum).

This is different than the function call mentioned at the end of 
the DIP by the review manager, which lowered it, format string 
and all in to a function call. Here (a proposal that came up in 
the original thread), only the format string gets the template 
call, avoiding the other difficulties brought up with the 
function call.


More information about the Digitalmars-d mailing list