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

Eliot Miranda eliot.miranda at gmail.com
Wed Aug 19 20:47:48 UTC 2015


Hi HM

On Wed, Aug 19, 2015 at 10:23 AM, Hans-Martin Mosner <hmm at heeg.de> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150819/7fdbb0f7/attachment.htm


More information about the Squeak-dev mailing list