What do you thing about this string interpolation idea

Jonathan Marler johnnymarler at gmail.com
Mon Dec 10 18:49:44 UTC 2018

On Monday, 10 December 2018 at 18:44:48 UTC, Steven Schveighoffer 
> On 12/10/18 12:43 PM, Jonathan Marler wrote:
>> It can also have some pretty unexpected results.  For example, 
>> having a variable reference an outerscope instance instead of 
>> the local one:
> Meh, I don't see this as really a problem or unexpected -- 
> depending on how you look at the feature.
> In general, anyone who wants to use this technique would know 
> to mixin the string in the function they are going to use it.
> I'm not saying the proposed DMD update and DIP isn't worth it, 
> as even with the better call syntax, this is going to tax the 
> CTFE engine hard, compared to what the compiler deals with (and 
> that code already is there). But it's worth exploring how far 
> we can get with this idea, to see the limitations and benefits. 
> Maybe it solidifies the position that we need it in the 
> language instead of the library.
> -Steve

Yeah I agree we should explore this and try to find other options 
besides the new string literal syntax.  But for me, this is 
reason enough not to use this technique in my code.  It means 
that at any point when I see the "interpolate!(...)" call, I have 
to follow it back up to where mixin(enableInterpolate) appears 
and make sure it's in my scope and not an outer one.  That's 
worse than making sure to free memory/resources every time you 
allocate them, and the amount of bugs that causes is bad enough.  
Any time your code depends on other code outside of itself you 
introduce more technical debt from the mental burden it takes to 
verify that code upon reading. Sometimes you can prevent that, 
but in this case I'd rather not use interpolation at all then 
introduce this kind of technical debt.

More information about the Digitalmars-d mailing list