phobos / tango / ares

Sean Kelly sean at f4.ca
Sat Feb 10 16:41:07 PST 2007


Bill Baxter wrote:
> 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?

Nope.  That's a good idea.


Sean


More information about the Digitalmars-d-learn mailing list