Why do the Class Variables get sorted alphabetically?

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

Why do the Class Variables get sorted alphabetically?

cbc
I create a class with variables:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A D E C B'
poolDictionaries: ''
category: 'Example'
(in that order, because that is the right order).

As soon as I save the class:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A B C D E'
poolDictionaries: ''
category: 'Example'

Why?

Note that the instance variables aren't sorted.

(using 5.0 - not sure if that is relevant or not)

-cbc


Reply | Threaded
Open this post in threaded view
|

Re: Why do the Class Variables get sorted alphabetically?

Hans-Martin Mosner
Am 19.08.2015 um 18:58 schrieb Chris Cunningham:
I create a class with variables:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A D E C B'
poolDictionaries: ''
category: 'Example'
(in that order, because that is the right order).

As soon as I save the class:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A B C D E'
poolDictionaries: ''
category: 'Example'

Why?

Note that the instance variables aren't sorted.

(using 5.0 - not sure if that is relevant or not)

-cbc



    
instance variables are ordered (their order determines their inst var slot index, so Smalltalk can't just shuffle them around).
Class variables are keys in a Dictionary, so essentially unordered. To make it easier for users to find a given class variable in the definition, Smalltalk sorts them alphabetically (otherwise the order could change inexplicably when the Dictionary would be rehashed after a new one is inserted.)

Cheers,
Hans-Martin


Reply | Threaded
Open this post in threaded view
|

Re: Why do the Class Variables get sorted alphabetically?

Eliot Miranda-2
Hi HM

On Wed, Aug 19, 2015 at 10:23 AM, Hans-Martin Mosner <[hidden email]> wrote:
Am 19.08.2015 um 18:58 schrieb Chris Cunningham:
I create a class with variables:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A D E C B'
poolDictionaries: ''
category: 'Example'
(in that order, because that is the right order).

As soon as I save the class:

Object subclass: #ClassOrderExample
instanceVariableNames: 'a d e c b'
classVariableNames: 'A B C D E'
poolDictionaries: ''
category: 'Example'

Why?

Note that the instance variables aren't sorted.

(using 5.0 - not sure if that is relevant or not)

-cbc



    
instance variables are ordered (their order determines their inst var slot index, so Smalltalk can't just shuffle them around).
Class variables are keys in a Dictionary, so essentially unordered. To make it easier for users to find a given class variable in the definition, Smalltalk sorts them alphabetically (otherwise the order could change inexplicably when the Dictionary would be rehashed after a new one is inserted.)

Also, sorting means that code comparison (e.g. on loading a package to identify changes) isn't confused by different permutations of the same set of class variables.

_,,,^..^,,,_
best, Eliot