[squeak-dev] Object>>printOn: refined.

Trygve Reenskaug trygver at ifi.uio.no
Wed Jun 3 12:18:06 UTC 2020


My sincere thanks for many thoughtful comments on my small contribution. 
I learned a lot from them. It is clear that my /printOn/:-method should 
not be included in a release image due to the repercussions on existing 
documentation and training courses also because it will only be useful 
to some but confusing to others.

Your comments made it clear that the method's usefulness depends on your 
mental model of a Squeak execution. My slogan expresses my own model: 
/"The essence of object orientation is that objects collaborate to 
achieve a goal."/ I clearly need to identify the objects when I see 
them. I understand that other people have other models and need other 
debugging aids. I believe some people don't need my /printOn:/ variant 
because they simplify things by merging the concepts of class and 
instance: "This class sends /open /to that class." It works well as long 
as you can get away with it.

The /printOn/:-method does not add to the complexity of the 491 methods 
of class Object; it merely modifies one of them. The method is harmless 
in that it does not influence program execution. It is just an advanced 
debugging aid that shows up wherever an object is visible, e.g., in an 
inspector, debugger, or Transcript (/dpsTrace:/). The title of an 
Inspector is just one example. It is useful whenever it is necessary to 
distinguish between several instances of the same class and also when 
one common object must be referenced by many.
An example of the latter is when all the panes of a System Browser 
reference the same model objects, as illustrated in the screen dump 
below. (The dump shows inspectors on the five panes of a System Browser 
carefully positioned on the Squeak screen. Notice that all of them have 
the same model object ).




Copy the method into your image if you want to try it, reset to the 
original version if you don't like it.
--Trygve


On 2020.06.02 14:10, Trygve Reenskaug wrote:
> I find it frustrating to open 3 inspectors on different objects, all 
> of them titled 'aString' (or whatever),
> IMO, it is much better to open them on the 3 objects: [1234] aString, 
> [3456] a String, [4567 a String.
> The numbers in square brackets stand for the objects /oop/, actually 
> its /identityHash/. They can be a 7-digit numbers; much too long for 
> my short-time memory to hold many of them. I therefore truncate the 
> number to 4 digits, accepting that I may, in rare cases, get 2 objects 
> with the same identifier.
>
> I'm running 'Squeak5.3'.
>
>     *Object>>printOn: aStream*
>             "Append to the argument, aStream, a sequence of characters
>     that identifies the receiver."
>             " The previous version identified the class, not the
>     instance "
>             " This new version identifies the instance with its oop. "
>             " I arbitrarily truncate the oop to 4 digits to simplify
>     reading. "
>
>             | title |
>             title := self class name.
>             aStream
>                 nextPutAll: '[' , (self asOop printString truncateTo:
>     4) , ']' ;
>                 nextPutAll: (title first isVowel ifTrue: ['an ']
>     ifFalse: ['a ']);
>                 nextPutAll: title
>
> Enjoy
> --Trygve
> -- 
>
> /The essence of object orientation is that objects collaborateto 
> achieve a goal. /
> Trygve Reenskaug mailto: trygver at ifi.uio.no <mailto:%20trygver at ifi.uio.no>
> Morgedalsvn. 5A http://folk.uio.no/trygver/
> N-0378 Oslo http://fullOO.info
> Norway                     Tel: (+47) 468 58 625
>

-- 

/The essence of object orientation is that objects collaborateto achieve 
a goal. /
Trygve Reenskaug mailto: trygver at ifi.uio.no <mailto:%20trygver at ifi.uio.no>
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo http://fullOO.info
Norway                     Tel: (+47) 468 58 625

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200603/88792277/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aokabaelhoipocdn.png
Type: image/png
Size: 907183 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200603/88792277/attachment-0001.png>


More information about the Squeak-dev mailing list