Bug 691 – Object.print ought to be removed or at least deprecated
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2006-12-16T21:01:00Z
Last change time
2014-02-15T13:29:11Z
Assigned to
bugzilla
Creator
smjg
Comments
Comment #0 by smjg — 2006-12-16T21:01:38Z
The Object class contains the method
void print();
Its flaw is that it gives the application using it no choice of what to output to. Different applications, or even parts of the same application, may want to output variously to stdout, stderr, a log file or a GUI window, just to name a few possibilities.
And it serves no real purpose. If a program wants to output the string representation of something, it can use .toString directly, which is much more versatile.
While in theory print could be overridden e.g. to show more information than would appear in the toString, this isn't the way to do it. Better would be for individual classes that want to do this to define a function such as toLongString. A class designer may also want to have the information output piece by piece to avoid having to allocate enough memory to hold the whole output at once - again, such a class would define its own print function. Preferably one that takes an OutputStream parameter rather than having the destination hard-coded as with the current Object.print.
I therefore agree with the proposals of various people that it should be got rid of. Partly because of its lack of practical use, but mainly because of its flaw. It should at least be deprecated ASAP. Removing it altogether would require a recompile, but at least if this is done before 1.0 then it would save having to recompile later.
Comment #1 by smjg — 2007-04-29T09:20:55Z
Why does this depend on issue 341? If we're going to get rid of it, we don't want to document it, do we?
Comment #2 by bugzilla — 2008-12-08T16:44:33Z
This has been removed from D 2.0. It won't be removed D 1.0 because of backwards compatibility issues.