Object: Identity vs. Environment

Andres Valloud sqrmax at comcast.net
Mon Jun 9 06:05:24 UTC 2003


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

Andres.



More information about the Squeak-dev mailing list