DIP9 -- Redo toString API

spir denis.spir at gmail.com
Sun Nov 21 12:38:28 PST 2010


On Sun, 21 Nov 2010 18:21:48 +0100
Don <nospam at nospam.com> wrote:

> spir wrote:
> > 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
> 
> The efficiency issues are important,

1. Please bring concrete cases of apps that do not work well because of toString and would work fine just by replacing it with writeTo. 
2. That a given %age of apps suffer of it is not enough reason for privating other of their favorite tool, esp one that is anchored in everyday practice.
3. Is anyone forced to use toString? Why don't people who refuse toString use any other tool they like better? Some argue that we don't lose anything... the same applies for you.
4. If you want another default and builtin tool, why not have both?
5. 99% of "hand-made" string construction & output happen at the end of a process, before waiting for user input, or other situations where efficiency is no more that blank word.

Man, this is simply not fair.

> but are not the primary motivation.
> toString() is just wrong. The idea that there is ONE AND ONLY ONE 
> textual representation of an object, is, frankly, idiotic.

Who argues for "ONE AND ONLY ONE textual representation"? And how does writeTo allow better textual diversity, anyway (aside passing format specs, which could as well fit toString)? Where is the argument?
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. But, yes, you are right and we all have been wrong for 20 years: toString is junk. Thank you for this sudden enlightenment.

(Aside this point, I guess we all are used to build various textual representations of all kinds of objects, for various uses. The one provided by toString beeing special in that it is implicitely invoked by some very handy tools like %s. So handy that I )

denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list