Just another example of missing string interpolation
Steven Schveighoffer
schveiguy at gmail.com
Fri Oct 20 13:45:40 UTC 2023
On Friday, 20 October 2023 at 07:14:45 UTC, Walter Bright wrote:
> This code can be adapted to do whatever output schema one
> wants. Compare the tuple generated by DIP1027:
>
> ```
> tuple("format %s %s sss", abc, 73)
> ```
> and with YAIDIP:
> ```
> tuple(.object.imported!"core.interpolation".InterpolationHeader!("", "format ", "", abc, "", 73, "", " sss", ""), "", "format ", "", abc, "", 73, "", " sss", "")
> ```
If this is supposed to be a favorable comparison of 1027, this
has failed.
1027 requires runtime processing of a compile-time format string.
It requires that you implement escapes for the %s spec and for
literal %, or just know that your domain doesn't have a valid use
for %s normally (though this always can be proven to be a mistake
by users). It is not friendly to multiple interpolation strings
sent to the same function (how does the function know this is a
new header?)
YAIDIP or 1036, there is no discarding of the processing the
*compiler already did* to parse the format string. Think about
that -- with 1027 the compiler parsed the interpolation tuple,
and built a puzzle string for you to have to figure out what it
did during runtime.
Who cares what the generated tuple looks like? Nobody will see
it. Do you care what other lowerings in the compiler look like?
Because a lot of times they are god-awful monstrosities that
nobody would write themselves. Is that something to object to?
All the proposed solutions, including 1027, can be worked with
for most cases. It's just that the code to adapt 1027 to calls
except for printf and writef is awful. It doesn't handle other
situations at all.
And 1027 still has the problem of matching functions it shouldn't
match. Do you recall Adam's example of exception construction?
```d
throw new Exception(i"Invalid integer value in $file: $val");
```
-Steve
More information about the Digitalmars-d
mailing list