[squeak-dev] Why do the Class Variables get sorted alphabetically?

Hans-Martin Mosner hmm at heeg.de
Wed Aug 19 17:23:05 UTC 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150819/4f671f99/attachment.htm


More information about the Squeak-dev mailing list