DIP9 -- Redo toString API

spir denis.spir at gmail.com
Sun Nov 21 06:08:10 PST 2010


On Sun, 21 Nov 2010 03:17:57 -0800
Jonathan M Davis <jmdavisProg at gmx.com> wrote:

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

I'm usually not using toString(), it's supported by the language. What about format("%s:%s", a,b)? Will it still call toString implicitely, or writeTo a buffer, or what else?

Anyway, I cannot see any advantage in deprecating toString() for every programmer in every use case, just for hypothetical efficiency issues -- that have not yet been shown in concrete cases: an app that cannot work fine because of toString allocating on the heap. Let us free to use our favorite tools, please! Do not pretend & telling us what is best for us.
The solution is simple: toString() defaults to writeTo, writeTo defaults to toString. This also solves 2 "human" issue you evoke: that people are used to toString and know it very well, and that writeTo looks more intimidating.

As said in previous post, enhancing toString with a format specifier would be cool.

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list