phobos / tango / ares

Bill Baxter dnewsgroup at billbaxter.com
Sat Feb 10 06:43:43 PST 2007


Sean Kelly wrote:
> Kevin Bealer wrote:
>>
>> Okay -- I'm really sorry if any of this seems to have a negative tone. 
>> I hesitate to write this since I have a lot of respect for the Tango 
>> design in general, but there are a couple of friction points I've 
>> noticed.
>>
>> 1. writefln / format replacements
>>
>> Concerning standard output and string formatting, in phobos I can do 
>> these operations:
>>
>>   writefln("%s %s %s", a, b, c);
>>   format("%s %s %s", a, b, c);
>>
>> How do I do these in Tango?  The change to "{0} {1}" stuff is fine 
>> with me, in fact I like it, but this syntax:
>>
>>   Stdout.formatln("{0} {1} {2}", a, b, c);
>>   Format!(char).convert("{0} {1} {2}", a, b, c);
>>
>> Is awkward.  And these statements are used *all the time*.  In a 
>> recent toy project I wrote, I used Stdout 15 times, compared to using 
>> "foreach" only 8 times.  I also use the "format to string" idiom a lot 
>> (oddly enough, not in that project), and it's even more awkward.
> 
> The conversion modules seem to have slightly spotty API documentation, 
> but I think this will work for the common case:
> 
> Formatter( "{0} {1} {2}", a, b, c );
> 
> The Stdout design is the result of a lengthy discussion involving 
> overload rules and expected behavior.  I believe two of the salient 
> points were that the default case should be the simplest to execute, and 
> that the .format method call provided a useful signifier that an 
> explicit format was being supplied. 

Is there any reason not to make the format item's index also optional? 
So that
    Formatter("{} {} {}", a, b, c);
can be used?  I mean making it more like %s?

The meaning would just be "use the index (1+ the last one that 
appeared)" or 0 if it's the first to appear.

And then if you go there, it might be nice to have a way to say "same as 
the last item" or "last item +/- some index".  Maybe use +/- numbers.  So
    Formatter("{1} {+0} {-1}",a,b);
would be equal to
    Formatter("{1} {1} {0}",a,b);
I can't really think of when I'd use that though.  The {} I'd use for 
sure though.

Anyway, the positional references are great, and really a must have for 
any serious I18N usage, but in the original language the app is written 
in, things tend to appear in the order of the arguments.

--bb


More information about the Digitalmars-d-learn mailing list