Why nil needs class hierarchy protocol?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Why nil needs class hierarchy protocol?

Denis Kudriashov
Hi.

Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

It implemented like this:

UndefinedObject >>subclassesDo: aBlock
"Evaluate aBlock with all subclasses of nil.  Others are not direct subclasses of Class."

^ Class subclassesDo: [:cl | 
cl isMeta ifTrue: [aBlock value: cl soleInstance]].


So my question is: why it needs to be like that? And does it really needed?

I removed all this methods and not saw any problem. 
Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Nicolai Hess-3-2


2016-07-26 15:08 GMT+02:00 Denis Kudriashov <[hidden email]>:
Hi.

Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

ProtoObjects superclass is nil, so maybe it just should behave the same way for all other objects.

ByteString superclass subclasses includes: ByteString. "true"

ProtoObject superclass subclasses includes: ProtoObject. "true"

 

It implemented like this:

UndefinedObject >>subclassesDo: aBlock
"Evaluate aBlock with all subclasses of nil.  Others are not direct subclasses of Class."

^ Class subclassesDo: [:cl | 
cl isMeta ifTrue: [aBlock value: cl soleInstance]].


So my question is: why it needs to be like that? And does it really needed?

I removed all this methods and not saw any problem. 

Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Eliot Miranda-2
Hi Nicolai,

On Jul 26, 2016, at 6:33 AM, Nicolai Hess <[hidden email]> wrote:



2016-07-26 15:08 GMT+02:00 Denis Kudriashov <[hidden email]>:
Hi.

Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

ProtoObjects superclass is nil, so maybe it just should behave the same way for all other objects.

ByteString superclass subclasses includes: ByteString. "true"

ProtoObject superclass subclasses includes: ProtoObject. "true"

Sorry to sound harsh but that's no sense.  ProtoObject doesn't have a superclass.  This is indicated by ProtoObject superclass answering nil, where nil is the object that represents being undefined.

It is (as Denis points out) a bug, showing some confusion, to try and program around this one case by adding class protocol to the  undefined object.  A horrible hack.

Denis, you're right; that behaviour should be deleted.

 

It implemented like this:

UndefinedObject >>subclassesDo: aBlock
"Evaluate aBlock with all subclasses of nil.  Others are not direct subclasses of Class."

^ Class subclassesDo: [:cl | 
cl isMeta ifTrue: [aBlock value: cl soleInstance]].


So my question is: why it needs to be like that? And does it really needed?

I removed all this methods and not saw any problem. 

Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Peter Uhnak
Well the class definition of ProtoObject is

ProtoObject subclass: #ProtoObject
slots: {  }
classVariables: {  }
category: 'Kernel-Objects'.
ProtoObject superclass: nil

So I guess by setting the superclass to nil, it was added as a child, since UndefinedObject is still just an object :)

On Tue, Jul 26, 2016 at 4:09 PM, Eliot Miranda <[hidden email]> wrote:
Hi Nicolai,

On Jul 26, 2016, at 6:33 AM, Nicolai Hess <[hidden email]> wrote:



2016-07-26 15:08 GMT+02:00 Denis Kudriashov <[hidden email]>:
Hi.

Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

ProtoObjects superclass is nil, so maybe it just should behave the same way for all other objects.

ByteString superclass subclasses includes: ByteString. "true"

ProtoObject superclass subclasses includes: ProtoObject. "true"

Sorry to sound harsh but that's no sense.  ProtoObject doesn't have a superclass.  This is indicated by ProtoObject superclass answering nil, where nil is the object that represents being undefined.

It is (as Denis points out) a bug, showing some confusion, to try and program around this one case by adding class protocol to the  undefined object.  A horrible hack.

Denis, you're right; that behaviour should be deleted.

 

It implemented like this:

UndefinedObject >>subclassesDo: aBlock
"Evaluate aBlock with all subclasses of nil.  Others are not direct subclasses of Class."

^ Class subclassesDo: [:cl | 
cl isMeta ifTrue: [aBlock value: cl soleInstance]].


So my question is: why it needs to be like that? And does it really needed?

I removed all this methods and not saw any problem. 


Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Denis Kudriashov
In reply to this post by Nicolai Hess-3-2

2016-07-26 15:33 GMT+02:00 Nicolai Hess <[hidden email]>:
Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

It is true only for ProtoObject. If you will create another class with nil superclass, you will not see it here
Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Denis Kudriashov
In reply to this post by Eliot Miranda-2

2016-07-26 16:09 GMT+02:00 Eliot Miranda <[hidden email]>:
Sorry to sound harsh but that's no sense.  ProtoObject doesn't have a superclass.  This is indicated by ProtoObject superclass answering nil, where nil is the object that represents being undefined.

It is (as Denis points out) a bug, showing some confusion, to try and program around this one case by adding class protocol to the  undefined object.  A horrible hack.

I think so too :)
Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Eliot Miranda-2
In reply to this post by Denis Kudriashov


On Jul 26, 2016, at 8:56 AM, Denis Kudriashov <[hidden email]> wrote:


2016-07-26 15:33 GMT+02:00 Nicolai Hess <[hidden email]>:
Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

It is true only for ProtoObject. If you will create another class with nil superclass, you will not see it here

Bullseye.  
Reply | Threaded
Open this post in threaded view
|

Re: Why nil needs class hierarchy protocol?

Denis Kudriashov
Done 18820

2016-07-26 18:22 GMT+02:00 Eliot Miranda <[hidden email]>:


On Jul 26, 2016, at 8:56 AM, Denis Kudriashov <[hidden email]> wrote:


2016-07-26 15:33 GMT+02:00 Nicolai Hess <[hidden email]>:
Look at UndefinedObject instance side methods. You will see class hierarchy protocol. For example nil understands #subclasses message:

nil subclasses "==> {ProtoObject}"

It is true only for ProtoObject. If you will create another class with nil superclass, you will not see it here

Bullseye.