DIP9 -- Redo toString API

Daniel Gibson metalcaedes at gmail.com
Mon Nov 22 12:57:54 PST 2010


spir schrieb:
 > toString is so wrong that it's often the first method most users of most
 > OO language implement -- to ensure vivious bugs won't pass unseen -- to
 > be able to combine representations into more complete representations--
 > to construct useful feedback about their app in general.
 > When a type has only 2 methods thet're the constructor and toString.

So?
In the future the first implemented method will be writeTo().
Sure, "void writeTo(scope void delegate(in char[] data) sink, string format) 
const" looks more intimidating than "string toString()", but once you've seen an 
example how this is to be implemented (like struct Pair from the DIP) that's not 
a problem anymore.

"formattedWrite(sink, "blahfoo %s", foo);" is as easy as
"return format("blahfoo %s", foo);"
Isn't it?

Cheers,
- Daniel


More information about the Digitalmars-d mailing list