PHP-style (embedded variables) print statements

Don Clugston dac at nospam.com.au
Thu May 31 05:59:35 PDT 2007


Jarrett Billingsley wrote:
> "Don Clugston" <dac at nospam.com.au> wrote in message 
> news:f3lt8d$2je5$1 at digitalmars.com...
>> Note that unlike a tuple solution, it does not cause any template bloat.
>> Also doesn't have some of writefln's pitfalls (the case where a string
>> contains a % character).
> 
> You can't print out the string using %s?

The problem is that it's so easy to forget the %s, and have a latent bug that 
lies undetected.

> 
>> Opinions? Is something like this worth considering as an alternative to
>> writefln, and to Tango's C# formatting and whisper syntax?
> 
> Not to burst your bubble, but I've just never found variable interpolation 
> to be all that useful, mostly because it's not really obvious (unless you 
> have some kind of fancy code highlighter) when something's being 
> interpolated, and because there's already syntaxes that look fine to me. 
> Some people like it though.

Yes, these are the main issues. I know that people have requested it in the past 
(and it was also touted as something Nemerle can do which D can't <g>). 
Personally, I thought it was one of very few interesting features of PHP.

There's probably a syntax which would be a bit more obvious, but still...
BTW, do you feel the same way about the C# syntax? Is it obvious enough?

mixin interpolation:
   mixin(dprint("current=$i next=$(i+1) const=$(k*3) $str"));

C# (available in Tango):
   print("current={0} next={1} const={2} {3}", i, i+1, k+3, str));
Phobos:
   writef("current=", i, " next=", i+1, " const=", k+3, " ", str);



More information about the Digitalmars-d mailing list