[Cuis-dev] nil subclasses (Re: clever or silly idea?)

Juan Vuletich juan at cuis.st
Wed Jun 12 06:22:41 PDT 2024


Hi Folks,

On 6/11/2024 9:45 PM, Andres Valloud via Cuis-dev wrote:
> Make a subclass of nil called Parrot.  Implement only
>
>     doesNotUnderstand: aMessage
>
>         ^self
>
> and then evaluate the following.
>
>     Parrot new ifTrue: [#haha] ifFalse: [#hehe]
>
> Explain the behavior you see.
>
> Side comments...
>
> 1.  It should not be that hard to create a new subclass of nil, 
> substituting in ProtoObject when it was not requested is unhelpful.
>
> 2.  I could not redefine an existing class to have a superclass of nil 
> because the process sends removeObsoleteSubclass: to the superclass of 
> the class in question, which in this case is nil.  Juan, this looks 
> like new code you wrote recently, you may want to review what happened 
> here.

1. That's a good question. Is it helping or not? Shouldn't a subclass of 
ProtoObject be used instead? Not really sure. I think I've never seen a 
case where having ProtoObject as superclass is more a problem that a 
convenience.

2. Fixing that right now. Done. Fix at GitHub.

3. This is another issue. If you see the definition of ProtoObject in 
the browser, or the comment at UndefinedObject >> 
#subclass:instanceVariableNames:classVariableNames:poolDictionaries:category: 
, the recommended way to create the class is to make it subclass of 
Undefined object, and then do `Parrot superclass: nil`. This is 
disturbing. Parrot will have superclass == nil, but will be included in 
the subclasses array of ProtoObject. The superclass / subclass invariant 
is broken. This code has been there for 25 years, and I wouldn't modify 
it lightly. Moreover, if you evaluate the suggested class definition, it 
will appear repeated times, like ProtoObject subclasses = #(Object 
MessageCatcher BreakingMethodWrapper Parrot Parrot Parrot Parrot) . So 
something has to be done.

I guess the only subclass of nil created in 25 years is ProtoObject 
itself...

-- 
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich



More information about the Cuis-dev mailing list