DIP1027 - Easy String Interpolation implementation

Walter Bright newshound2 at digitalmars.com
Mon Oct 23 19:25:35 UTC 2023


On 10/23/2023 1:34 AM, Juraj wrote:
> Sorry for being repetitive, but as you made an implementation only after the DIP 
> was rejected, I figured it would be beneficial to show some real examples.

Thank you for posting them. Consider some more examples:

```
import std.stdio;

void main()
{
     writefln("hello %d", "betty"); // compiles just fine (exception at runtime)
     writeln("hello %s", "betty");  // compiles and runs!
}
```

I've made many mistakes like that. (Sorry, Betty!) I bet a lot of people have. 
There's no problem fixing them, as it's pretty obvious when a format string is 
in the output.

None of them resulted in memory unsafe code, and why would they? The generated 
strings are still checked for memory safety like any other code.

The result isn't type unsafe, either. The tuple elements are checked for type 
safety just like any other arguments.

Of course, printf isn't 100% checkable for memory safety (though D's checks plug 
most of those holes), so it's a bit unfair to blame DIP1027 for that. I did 
suggest that D's printf format checker could be enhanced to modify the arguments 
to make it memory safe, but that elicited no interest.

The fundamental issue here is that format strings are typed as strings. That 
issue is not going away. It is transferable to any attempt to use tuples as 
function arguments. There's a strong desire to use tuples a lot more in D (by 
adding the ability for functions to return tuples). Placing too much weight on 
this complaint would seem to seriously cripple use of tuples.

The complaint is also transferable to mixins. After all, mixins can generate 
arguments that are incorrect. mixins take string arguments, too, and it is up to 
the user of the mixin to ensure the string is formed properly.


> Anyway, all these silent bugs are not present in Adams implementation.

Adam strongly criticized my review of YAIDIP because that was not how his 
implementation worked. I spent several hours studying YAIDIP, and can't help 
being annoyed at the waste of time. I don't know how his implementation works, 
because there is no specification for it.

I await Adam writing a specification for it so I can review it.


More information about the Digitalmars-d mailing list