[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing Objects



    Date: 6 May 87 22:01 PDT
    From: Masinter.pa@Xerox.COM

    Of the alternatives:

    a) All objects print out as #S, if you want different behavior, you
    override it

    b) By default, objects can't print themselves, and you have to provide a
    print function or else mixin a standard class

This is misleading.  87-002 requires that the implementation provide a default
method.  The issue in question is not whether objects can print themselves,
but what happens you feed the output of that to read.  Thus alternative b
should be stated as "By default, objects print something that signals an error
when read."  If I wanted to be parallel to that, but biased, I would state
alternative a as "By default, objects print something that creates a bogus
object when read."

    Consider three cases:

    1) object wants to print out as #S...
    2) object cannot be printed really -- it doesn't make sense to "read" it
    3) object wants to be printed in a special way

    Case 1: a is preferable, since what you want to do is already the
    default

    Case 2: b is only marginally better. In alternative a, you have to
    supply an error-if-you-print-me method or else you will get printing
    when you shouldn't really   --if your erroneously print something and
    try to read it back in, alternative b gives you an error at print time,
    while alternative a gives you an error later on in your program. 

Not so, since Common Lisp is missing the :readably argument to WRITE.
Alternative b gives you an error at read time, not print time.

    Case 3: it makes no difference, since you're supplying a print method.

    I think Case 1 is the most common in most of the program's I've seen
    anyway.

Not in the programs I've seen.  Leaving aside endless arguments about who's
seen what programs, and turning to design rationales: I think it is better
to signal an error when there is some question what people might want,
and provide a way for them to say what they want, than to lead them down
a garden path that ends up in a mysterious blowout because the system
guessed their intention wrong.  This is a general principle, but I think
it applies to this case.