DIP9 -- Redo toString API

Jonathan M Davis jmdavisProg at gmx.com
Sun Nov 21 03:17:57 PST 2010


On Sunday 21 November 2010 02:10:13 spir wrote:
> On Thu, 18 Nov 2010 17:21:20 -0500
> 
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote:
> > I just created a new D Improvement Proposal to fix the toString problem I
> > brought up several posts ago.
> > 
> > See: http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP9
> 
> Hello,
> 
> 
> [Sorry for a partly personal message, but I cannot help it. At first sight,
> my gut reaction in front of this proposal has been: no, nooo, NOOO!!! I
> waited a few days because, _surely_, I was missing or misinterpreting some
> basic point. But after several days and reads of the DIP, I still feel the
> same and nobody seems to address the issue; so here I go. Excuse the noise
> if I'm simply wrong. I feel ashamed to send that -- but let's be bold
> :-).]

You're not really losing toString(). to!string() would use writeTo() to convert 
objects to strings. writeln() and writefln() would use writeTo() to convert 
objects to strings (with the added benefit of potentially being able to use 
format specifiers other than %s - such as %d and %x for BigInt). format() would 
do the same.

You're not losing _anything_ out of the deal except that you wouldn't do 
obj.toString(). Instead you'd do to!string(obj).

The _only_ downside to it that I see is that it's going to be offputting to 
people to see writeTo()'s signature in comparison to toString(), and people will 
initially not understand how to just get a string like you currently would with 
toString() (similarly to your reaction). Once you understand how to using 
writeTo() to get a string, it should be quite easy and straightforward and not a 
problem at all. The end result will be more flexible and efficient, just 
potentially offputting until you understand how to use it.

- Jonathan M Davis


More information about the Digitalmars-d mailing list