[BioCocoa-dev] Peptides...

Charles PARNOT charles.parnot at stanford.edu
Tue Mar 29 17:47:43 EST 2005

At 17:38 -0500 3/29/05, Koen van der Drift wrote:
>On Mar 29, 2005, at 12:06 PM, Charles PARNOT wrote:
>>The problem is that in the proposed implementation, you return an NSArray, when in fact, it is a disguised NSMutableArray. This can easily bite us or the user back, for instance:
>Ah, now I see what you mean :)  Yes that could be a potential problem.  I can think of two solutions:
>Make the symbolArray ivar non-mutable, this would mean some additional chnages in the various init methods.  Or we return a mutable array from the accessor. I would prefer the second solution:
>- (NSMutableArray *)symbolArray
>	return symbolArray;
>Using Cocoa/ObjC conventions, I wouldn't call the accessor mutableSymbolArray but just the name of the ivar. Also, we can always add an additional accessor to get a real copy.
>I hope this answers your question?
>- Koen.

Yes, I agree it makes more sense at this stage to have simply:
- (NSMutableArray *)symbolArray
	return symbolArray;

And indeed we don't need the mutableSymbolArray method. And I would be completely happy with this :-)

The only little issue is we are trusting the user will read the docs and not mess up with the array. A real NSArray is nice, because it respects encapsulation much more.

If we make the symbolArray non-mutable, it almost means we have an immutable sequence... though we can always create a new array every time the sequence is modified and thus have the sequence be mutable. But that would not be very good for performance and it would become a problem in some other situations!

Anyway, my opinion is that at some point, we will want to have immutable and mutable versions of the sequence, as the user is then free to use the most appropriate object depending on what she is doing, in terms of performance.


Help science go fast forward:

Charles Parnot
charles.parnot at stanford.edu

Room  B157 in Beckman Center
279, Campus Drive
Stanford University
Stanford, CA 94305 (USA)

Tel +1 650 725 7754
Fax +1 650 725 8021

More information about the Biococoa-dev mailing list