Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-25 Thread Herby Vojčík
On 25. 7. 2019 4:27, Richard O'Keefe wrote: Comment 2. ?? This is a poor design.?? As it is, any object can replace the tracks of an artist ?? with *anything*.?? And even without doing that, any object can add and remove ?? items to an artist's tracks, even if the added items are not

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-25 Thread Herby Vojčík
On 24. 7. 2019 17:30, sergio ruiz wrote: hmm??? maybe this is cleaner.. tracks tracks ifNil: [ self tracks: OrderedCollection new ]. ^ tracks IMO, return ifNil: value is an understood and used idiom, so I'd say ^ tracks ifNil: [ tracks := ... ] is the most clean way. Maybe look at sender

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Richard O'Keefe
Comment 1. You probably meant to write tracks: aCollection ^tracks := aCollection Comment 2. This is a poor design. As it is, any object can replace the tracks of an artist with *anything*. And even without doing that, any object can add and remove items to an artist's tracks,

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Esteban Maringolo
I agree with that, but in some cases, like reading objects from an ORM, you would be creating lots of instances of objects that are going to be discarded right away. This would put no stress on GC since it would happen in the "new" space, but would consume more memory (although I never measured

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Richard Sargent
I will add that I prefer the static model to tell the truth about its data types. So, I prefer having an #initialize method which ensures the new object is created in a self-consistent way and anyone looking at it in an inspector will see useful and correct information. Leaving instance variables

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread sergio ruiz
> > tracks > ^tracks ifNil: [ tracks := OrderedCollection new ]. > > - one line > - does not mix using accusers and not using accessors. Okay, I totally get the subtlety now. I don’t even need an accessor. Thanks! peace, sergio photographer, journalist, visionary Public Key:

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Marcus Denker
> On 24 Jul 2019, at 17:30, sergio ruiz wrote: > > hmm… > > maybe this is cleaner.. > > tracks > tracks ifNil: [ self tracks: OrderedCollection new ]. > ^ tracks > I write these methods as tracks ^tracks ifNil: [ tracks := OrderedCollection new ]. - one line

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Paul DeBruicker
You should change your #tracks method to tracks ^tracks ifNil:[tracks:=OrderedCollection new] or tracks tracks ifNil:[self initializeTracks] ^tracks initializeTracks tracks:=OrderedCollection new. Then you don't have to worry about the implementation of #tracks: changing in the

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread sergio ruiz
hmm… maybe this is cleaner.. tracks tracks ifNil: [ self tracks: OrderedCollection new ]. ^ tracks > > > because your #tracks: returns self, not the collection value peace, sergio photographer, journalist, visionary Public Key: http://bit.ly/29z9fG0 #BitMessage

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread sergio ruiz
Oh! how about this: tracks: anObject tracks := anObject. ^ tracks ? > On Jul 24, 2019, at 10:48 AM, Sven Van Caekenberghe wrote: > > because your #tracks: returns self, not the collection value peace, sergio photographer, journalist, visionary Public Key:

Re: [Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread Sven Van Caekenberghe
because your #tracks: returns self, not the collection value > On 24 Jul 2019, at 16:46, sergio ruiz wrote: > > I'm implementing an instance variable as an OrderedCollection, and am doing > something idiotic. > > I have an Artist class. > > An Artist can have many tracks: > > tracks > ^

[Pharo-users] OrderedCollection as an instance variable

2019-07-24 Thread sergio ruiz
I'm implementing an instance variable as an OrderedCollection, and am doing something idiotic. I have an Artist class. An Artist can have many tracks: tracks ^ tracks ifNil: [ self tracks: OrderedCollection new ] tracks: anObject tracks := anObject Doing something like: a := Artist