Re: [Pyobjc-dev] Bridging NSMutableString, a compromise
Brought to you by:
ronaldoussoren
From: Jack J. <Jac...@cw...> - 2003-02-07 16:38:47
|
On Friday, Feb 7, 2003, at 11:14 Europe/Amsterdam, Just van Rossum wrote: > I've been doing some thinking, and now have some doubts that "fixing" > Python to allow mutable dict keys will solve everything. Biggest > problem: if we wrap an NSMutableString in a (mutable) unicode subclass, > how are we going to keep the two strings synchronized? > > Here's an idea for a compromise that might work and yet be convenient > to > work with from Python in the majority of cases. > > Problem: > > - We need NSStrings to work like Python strings as _much_ as possible. > > - We need access to the methods of the NSString, or to put it in other > words, we need to have full access to the native object, _especially_ > if > it's mutable. I've been thinking about it long and hard, but I don't see why the second assertion is true. And my feeling is that all the complexity comes from that assertion. If anything returning an NSString would (on the Python side) return a "NSString_Or_NSMutableString_Acting_Like_a_Python_String" object (NONALPS for short) then I think the requirements would be: - A NONALPS behaves as much as a Python string as possible. - A NONALPS can be passed where an NSString is expected, and then object identity of the original NS{Mutable}String is preserved on the ObjC side. - (corollary of the previous): a NONALPS can be cast to an NSString, whereby you get the original object, plus access to all the methods. - of course a NONALPS can be cast to a Python string, but this doesn't do any identity preserving (which isn't needed anyway). Note that I think we should specifically *not* allow passing a NONALPS where an NSMutableString is expected, or returning any NSMutableString coming from ObjC as a NONALPS. Mutable strings are un-Pythonic beasts, and the programmer should be aware of that. The only mutable strings that we want to represent as Pythonic string lookalikes are those returned in places where the promise was that we would get an NSString. I think it's a safe assumption that the code returning NSMutableString in stead of NSString will at least have the common decency not to modify the contents behind our back. -- Jack Jansen, <Jac...@cw...>, http://www.cwi.nl/~jack If I can't dance I don't want to be part of your revolution -- Emma Goldman |