Object: Identity vs. Environment

Joel Shellman joel at ikestrel.com
Mon Jun 9 07:54:05 UTC 2003


> May I remind readers that there are 18 #isFoo messages in Object,
> that half or more of them refer to "core" classes like Number or Stream,
> and that 2 or 3 of them would be quite easy to eliminate.
>
> 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.
>
> I *do* think that requiring people to write
>
>     ([anObject isNumber] on: MessageNotUnderstood do: [false])
>         ifTrue: [handle number]
>         ifFalse: [handle anything else]
>
> instead of just plain
>
>     anObject isNumber
>         ifTrue: [handle number]
>         ifFalse: [handle anything else]
>
> is (let me be tactful here) seriously misguided.

But you just said in your other email that isWebBrowser should not be in
Object. If that is the case, than if you call isWebBrowser there will be a
chance you'll get an MNU. You can propogate that all the way to the user, or
I would think somewhere in the code, you would want to take an appropriate
action because something "bad" happened.

That's all I was saying with that example.

Granted... anytime you send any message there is a chance you'll get an MNU.
Which in certain cases then... why not just assume that what you have is
what you expect and just send the message you expect it to support and not
bother with any #isFoo call at all? That's my missing suggestion #5 that
I've been pondering a little lately.

> It would be especially misguided when you are using an #isFoo method
> that is *not* defined in Object, so that a DNU would represent an
> actual error that you would definitely want to be told about!
> I would have to call this an abuse of the exception handling machinery.

Or rather, that's exactly my point.

> By all means, let's try very hard not to add methods to Object if we can
> avoid it.  But the present set of #isFoo messsages in Object are pretty
> harmless.  They are certainly far less destructive of clarity and good
> practice than all the alternatives that have been suggested.

I think we're in agreement in general, though again, my acceptable list
might be shorter than yours.

Part of what struck this off is that the #isFoo was described to me as an
accepted idiom. And placing it on Object by some was seen to be a fine thing
to do. My concern is that if #isFoo on Object becomes an accepted idiom than
proliferation of such would result in ultimately thousands of #isFoo's on
Object.

-joel



More information about the Squeak-dev mailing list