Re: [Pyobjc-dev] Calling methods on nil
Brought to you by:
ronaldoussoren
From: Martina O. <Ma...@Oe...> - 2003-05-11 15:49:16
|
Hi Bill - > When everything is working correctly 'message to nil silently eaten' > is a great convenience. When something somewhere unexpectedly returns > nil, it becomes an incredibly nasty pain to try and figure out exactly > where the problem might be. By the time it crops up, you may be many > cycles through the run loop away from where the problem actually is. Agreed. > In the context of PyObjC, I consider 'message to nil throws' to be a > feature (and not just because it is the Python way). Unfortunately Cocoa uses the "message to nil ignored" pattern without documenting it. For example, the AddressBook methods which return arrays of people, groups etc. may return nil instead of an NSArray. As these details are not mentioned in Apple's documentation, they are a trap for PyObjc programmers. One way to fix this might be to translate Cocoa's nil to Dinu's Null class. But this might break existing programs which now compare Cocoa return values to None. Also there might be round-trip problems (what happens if you stored a Python None in an NSMutableArray. When you retrieve it later, will you get None or a Null object?). Probably there will be more problems of this kind, similar to what we have seen with other conversions in the bridge. Therefore I prefer the existing behaviour. However, I suggest to document it more detailed than now (list known examples of Cocoa returning a "to be ignored" nil), and to add explicit tests for nil to the example and tests where appropriate. ciao Martina |