| |
 | Posted by d-bugmail | Permalink Reply |
|
d-bugmail 
| http://d.puremagic.com/issues/show_bug.cgi?id=691
Summary: Object.print ought to be removed or at least deprecated
Product: D
Version: 0.177
Platform: All
URL: http://www.digitalmars.com/d/archives/digitalmars/D/2558
6.html
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: bugzilla@digitalmars.com
ReportedBy: smjg@iname.com
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.
--
|