[Newbies] Array vs OrderedCollection

Michael van der Gulik mikevdg at gmail.com
Sun Apr 26 21:43:10 UTC 2009


On 4/27/09, Miguel Enrique Cobá Martínez <miguel.coba at gmail.com> wrote:
> Hi all,
>
> are there any reason to prefer:
>
> "adding 2 objects"
> array := Array with: anObject.
> array := array copyWith: aSecondObject
> "removing object"
> array := array copyWithout: aSecondObject.
>
> instead of:
>
> "adding 2 objects"
> oc := OrderedCollection new.
> oc add: anObject.
> oc add: aSecondObject.
> "removing object"
> oc remove: aSecondObject ifAbsent: []
>
> This in reference to
>
> Class >> addSubclass: and Class >> removeSubclass: methods


In this particular case, I think you've made a valid point. I can't
see any obvious reason why an OrderedCollection can't be used. My
first suspicion is that this code was written before
OrderedCollections were added to the system (i.e. in 1980 sometime).
It might also have been written this way to make sure that the image
could potentially run without an OrderedCollection class (e.g. when
bootstrapping an image or something).

The first three variables of Class (i.e. superclass, methodDict,
format) are special and accessed directly by the VM meaning that they
need to be carefully worked with, but as far as I know all of the
other instance variables can be toyed with. Just be careful though...
changing something here the wrong way is likely to break the compiler
or the image.

Gulik.

-- 
http://gulik.pbwiki.com/


More information about the Beginners mailing list