[Newbies] Array vs OrderedCollection

Miguel Enrique Cobá Martínez miguel.coba at gmail.com
Mon Apr 27 03:01:20 UTC 2009


Michael van der Gulik wrote:
> 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).
> 
Yes I thought that, as the Array is one of the special objects, and it 
was necessary to build the first version of OrderedCollection.

> 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.
> 
I don't have plans of modify those methods, just searching for 
implementations of parent/child pointers and in a thread, someone 
mentioned those methods as a good implementation.

> Gulik.
> 

Thank you,
Miguel Cobá


More information about the Beginners mailing list