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

Dennis dkorpel at gmail.com
Sun Feb 2 19:22:23 UTC 2020


On Sunday, 2 February 2020 at 18:43:20 UTC, Tove wrote:
> Sure @nogc works fine, but sometimes you want to use gc and 
> when you do, the language should help you to do the right thing.
>
> while(...)
>   my_fun(i"name: $firstname $lastname");
>
> If my_fun takes a string this would be terrible code, it should 
> not compile until you make a conscious choice:
> a) Performance is not important for my app. -> Let's add 
> toString()
> b) Add a new overload to my_fun that can handle interpolated 
> strings directly.

You know, maybe instead of trying to give D the reputation of a 
mechanically checked memory safe language, it should be marketed 
with something better:

Mechanically enforced premature optimization! ;)

In all seriousness, I understand that eagerly constructing new 
strings is a bad practice for performant code and that you want 
to discourage it. I just think that since D is also pretty good 
for quick scripts or fast prototyping, being able to quickly type 
an interpolated string to evaluate to `string` would be very 
convenient.

Personally I especially dislike always importing std.conv: text 
or std.string: format just to get an informative message for 
`throw new Exception("...")` or `assert(x, "...")`, so I hope 
interpolated strings can at least solve that.


More information about the Digitalmars-d mailing list