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
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
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,
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
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
>
> 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:
> 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
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
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
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:
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
> ^
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
12 matches
Mail list logo