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

Arine arine123445128843 at gmail.com
Wed Feb 5 06:48:43 UTC 2020


On Wednesday, 5 February 2020 at 06:07:21 UTC, Walter Bright 
wrote:
> To clarify:
>
> 1. the DIP is not specific to printf, writef, or SQL formats. 
> It has no knowledge of any of them. It isn't even specific to 
> calling a function. It simply produces a tuple expression, the 
> first of which is a format string constructed from 
> user-specified (not builtin) formats.
>
> The only exception is using %s if the user neglects to give a 
> specification.

     float a;
     double b;
     real c;
     int d;

     printf(i"$a $b $c $d");

So the above translates to:

     printf("%s %s %s %s", a, b, c, d);

This DIP is worse than I thought... All this just so you can say 
it doesn't rely on a library implementation detail?


> 2. printf-aware checking can be added, but that would (and 
> should) be an entirely orthogonal proposal, and would be 
> effective with or without interpolated strings, as it has 
> literally nothing to do with this DIP. A possible 
> printf-format-checker would be run *after* the lowering to the 
> tuple expression, and so would be equally effective for using 
> or not using interpolated strings.

Because of 1, I have to *COMPLETELY* disagree. There's no way in 
hell this DIP should move forward without a checker if you plan 
with functionality of 1. You're going to force people to label 
specifiers themselves, when the compiler knows full well what 
type they are passing? That's just rediculous. No other language 
does this. The whole point is to keep it clean where you can. A 
float should have a %f not a %s inserted into the format.

> 3. having the interpolator escape % by writing %% means that % 
> becomes "baked in" as a special character. This is a completely 
> unnecessary complication.

It causes unexpected behavior. It wouldn't be that big of an 
issue if printf and friend's format was checked.

> 4. I repeat that I only use printf as an example because it is 
> so well known and I don't have to spend a lot of time 
> explaining what printf is and how it works. Note that writefln 
> is also included as an example. There is nothing at all printf 
> or writef specific in the design.

Other than it uses '%s' and uses a format string with args. 
Something multiple people here have said they don't want. It is 
purposefully designed the way it is because of printf and friends.

In the summarization of the DIP:

> the implementation must be compatible with BetterC, meaning 
> printf and similar C functions

printf is a driving force behind the implementation. If you could 
ignore printf this would be implemented completely differently.

> 5. This proposal is not at all intended to be a substitute for 
> knowing how printf formatting works. You're still going to have 
> to remember to use %d for printing integers rather than %s or 
> %g. This alone suggests that the DIP is not focused on printf.

This is just so backwards. Why. Why not just use printf without 
interpolated strings at this point.

This is what happens when someone that doesn't understand a 
feature and what benefits it brings tries to implement it. I'm 
sorry if that's harsh but it's the truth.

> ----
>
> The DIP is minimalist. This is intentional, as it proposes a 
> very simple and straightforward rewrite of a literal into a 
> tuple expression. Understanding tuple expressions (an existing 
> D feature) is essential to understanding the DIP. This is a 
> technique called "lowering" and is a great way of simplifying 
> the semantics of a language and reducing corner cases and 
> implementation bugs. Other examples:
>
> 1. the compiler rewrites 'while' loops into 'for' loops
>
> 2. the compiler rewrites RAII constructions into `try-finally` 
> constructions
>
> In fact, the compiler could profit from doing a lot more 
> lowering transformations.

The user doesn't have to interact with any of those. The user 
does have to interact with the result of an interpolated string 
as defined in this DIP. It isn't hidden from them.

     string v = i"value = $value";

A user isn't going to expect that to be:

     string v = ("value = %s", value);

You are lowering it for one minor use case where it is convenient 
, and then causing ugly behavior everywhere else. Not to mention 
it doesn't even do it properly, cause if you want to use a float 
you have to manually put %f yourself.




More information about the Digitalmars-d mailing list