Semantics of toString
    Don 
    nospam at nospam.com
       
    Thu Nov  5 21:34:57 PST 2009
    
    
  
Nick Sabalausky wrote:
> "Don" <nospam at nospam.com> wrote in message 
> news:hcvf9l$91i$1 at digitalmars.com...
>> Justin Johansson wrote:
>>> So what does "toString" mean to you?
>> It's a hack from the early days of D. Should be unavailable unless 
>> the -debug flag is set, to discourage people from using it. I hate it.
>>
> 
> What don't you like about it?
> 
It cannot even do the most basic stuff.
(1) You can't even make a struct that behaves like an int.
struct MyInt
{
     int z;
     string toString() { .... }
}
void main()
{
    int a = 400;
    MyInt b = 400;
    writefln("%05d %05d", a, b);
    writefln("%x %x", a, b);
}
(2) It doesn't behave like a stream. Suppose you have XmlDoc.toString()
You can't emit the doc, piece by piece. You have to create the ENTIRE 
string in one go!
    
    
More information about the Digitalmars-d
mailing list