Re: [Pyobjc-dev] NSString & mutability
Brought to you by:
ronaldoussoren
From: Just v. R. <ju...@le...> - 2003-02-04 20:57:15
|
bb...@ma... wrote: > Nice hack, but.... > > What about all the code that might return a mutable string depending > on how the developer exercises the API? Are you willing to assume > that every getter and setter that internally makes a immutable copy > of the set string value? i.e. that... > > .... [fooObject setMyNameIs: someRandomMutableString]; return > [fooObject myNameIs] .... > > .... that -myNameIs will return an immutable string? I'm totally willing to accept a surprise like that. I don't even see the problem when using such an API from Python: you call fooObject.setMyNameIs_() with a Python string, you call myNameIs() and get a Python string. Same string, different id. No problem in Python. Can you please give an example of an _actual_ problem? I'll have a go myself: Let's assume the API does the reverse: it takes an immutable string, yet returns its internal mutable copy, although myNameIs is declared to return an NSString. Now there _is_ a surprise: instead of a 100% equivalent string we get an NSMutableString instance. Ok, a surprise, but is it so bad? If the object internally uses a mutable string, it's likely that this is clear from the nature of the object (eg. it's some sort of editor for the string). So I still think such a surprise will be rare. > See this message -- it is still quite relevant. Mike Ferris is one > of the guys who helped write the AppKit and Project Builder. > > http://www.omnigroup.com/mailman/archive/macosx-dev/2000-May/001886. > html It's an example of NSArray, which we don't convert, so we live dangerously anyway in PyObjC as we don't even have the hint from the header that we _shouldn't_ mutate even if it is mutable. Just |