[BioCocoa-dev] Peptides...
Charles PARNOT
charles.parnot at stanford.edu
Tue Mar 29 12:06:43 EST 2005
>The original issue for the Peptides example is not the difference between immutable and mutable. Instead, the issue was that the accessor symbolArray returned a copy of the symbolArray, instead of just a pointer to that array, which is usual the case with accessors. Copying the array highly slowed down the Peptides calculation, while it was not necessary at all to create a copy. Therefore I suggested that we have the standard accessor:
>
>- (NSArray *)symbolArray
>{
> return symbolArray;
>}
>
>
>If the user really needs a copy of the array, there are at least two possibilities: 1. we supply an additional accessor that returns a copy (using [[symbolArray copy] autorelease]) 2. the user uses the standard accessor, and creates the copy herself.
>
>The mutable/immutable question is unrelated to this.
>
>- Koen.
OK, sorry I was still confusing. I will try to make it shorter and more to the point this time ;-)
I am completely aware of the optimization issue, coming from the copy (this is the kind of issue that immutable objects are supposed to address, actually, but I will keep that for later!).
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:
BCSequence *seq=[BCSequence sequenceWithString:@"ATGT"];
NSArray *symbols=[seq symbolArray];
int n=[symbols count];
[seq removeSymbolAtIndex:1];
BCSymbol *last=[symbols objectAtIndex:n]; //UNEXPECTED EXCEPTION
Don't you guys think this is an issue? Sorry if I am insisting, but you have not answered that particular point yet :-)
charles
--
Help science go fast forward:
http://cmgm.stanford.edu/~cparnot/xgrid-stanford/
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