Object: Identity vs. Environment
Joshua 'Schwa' Gargus
schwa at cc.gatech.edu
Mon Jun 9 06:44:50 UTC 2003
On Sun, Jun 08, 2003 at 11:05:24PM -0700, Andres Valloud wrote:
> > I really don't see anything evil about Object>>isNumber or Object>>isString;
> > numbers and strings are core parts of the language and it seems fair enough
> > for an object to know it isn't one.
>
> The bad part about these messages is that numbers and strings already
> "know" what they are by virtue of their behavior, and in the case of
> Smalltalk, by virtue of their class which specifies their behavior. It
> would be even better to eliminate the isFoo + ifTrue/ifFalse construct
> with polymorphism, i.e.:
>
> "in the context of doing foo"
> anObject isWhatever
> ifTrue: [this foo action]
> ifFalse: [that foo action]
>
> becomes
>
> "in the context of doing foo"
> anObject fooAction
>
> where
>
> Whatever>>fooAction
>
> "this foo action"
>
>
> Object>>fooAction
>
> "that foo action"
>
>
> On top of cleaner and more intention revealing code, you get speedups
> because it's no longer necessary to determine the value of a boolean
> expression at runtime using ifTrue/ifFalse. The meaning is in the
> receiver - cf. how booleans are implemented.
But you might have a dozen methods with isFoo + ifTrue/ifFalse. Then
you would need Object>>fooAction1, Object>>fooAction2, etc.
Joshua
>
> Andres.
More information about the Squeak-dev
mailing list
|