Thread overview
[Issue 691] New: Object.print ought to be removed or at least deprecated
Dec 17, 2006
d-bugmail
Apr 29, 2007
d-bugmail
Dec 08, 2008
d-bugmail
December 17, 2006
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.


-- 

April 29, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=691





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


-- 

December 08, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=691


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.


--