String Interpolation

Imperatorn johan_forsberg_86 at hotmail.com
Thu Oct 26 18:10:50 UTC 2023


On Thursday, 26 October 2023 at 16:42:23 UTC, Arafel wrote:
> On 26/10/23 18:14, bachmeier wrote:
>> I'd agree if the only thing I cared about is good language 
>> design and didn't care at all about usability. Why not this?
>> 
>> |import std.format; string s = $"Hello, ${world}"; |
>> 
>> Anyone that wants what's currently on offer could still do 
>> this if they want:
>> 
>> |string s = i"Hello, ${world}".format; |
> Also, not allowing this would result confusing to new users for 
> no good reason: you'll have to explain to them why 
> `write(i"....");` works, but `string s = i"....";` doesn't, and 
> how `i"..." isn't like `r"..." or `q"[...]"`.
>
> And then, if I have to do `i"Hello, ${world}".format`, I can 
> already just as well do `mixin(i!"Hello, ${world}")`. This 
> doesn't require any change to the language and has the 
> advantage (as a user) that it's a library solution and I can 
> pick the one that best suits my needs.

I'm replying to you here Arafel, but it's meant as a general 
comment.

As someone who has been developing for many years in both small 
companies and large, using everything from C, C++,(Visual) Basic, 
Erlang, Nim, Python, C#, Julia, PHP and Perl, I and many others 
know what works and what doesn't.

It's quite simple.

Keep it simple for the user. Have ergonomic syntax. Show that you 
care about the users feedback. Be reasonably performance, stable 
and safe.

The language exists for the users.

Nothing will change that fact, no matter what sequence of letters 
you put together.

And the users are saying, that if we should implement SI, there 
should exist an ergonomic way to get a string from the expression.

The users are not saying that that must be the *only* way, just 
that a way should exist that does not break the common interface. 
Many users are not in the forums at all btw.

Now, you can choose to ignore this, but in the end the same thing 
always happens. The users choose another language that is closer 
to the familiar interface.

The users don't care at all about what's good or bad under the 
hood.

They just care about how they use something.

And having to do an extra step in one language but not all the 
other breaks the common interface.

It's nothing more than that. So simple.

It might turn out that string interpolation is not worth it in D. 
Ok, then that's a decision that could be made.

But that decision should be made after you understand the 
consequences.

Also saying that it's the users loss if they move to another 
language, I must ask, are you sure about that?


More information about the Digitalmars-d mailing list