www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 691] New: Object.print ought to be removed or at least deprecated

reply d-bugmail puremagic.com writes:

           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
        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

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.

Dec 16 2006
next sibling parent d-bugmail puremagic.com writes:

------- Comment #1 from smjg iname.com  2007-04-29 09:20 -------
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?

Apr 29 2007
prev sibling parent d-bugmail puremagic.com writes:

bugzilla digitalmars.com changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

------- Comment #2 from bugzilla digitalmars.com  2008-12-08 16:44 -------
This has been removed from D 2.0. It won't be removed D 1.0 because of
backwards compatibility issues.

Dec 08 2008