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

Re: Printing Objects

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

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

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. 

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