Re: [Pyobjc-dev] Calling methods on nil
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-05-11 10:14:53
|
On Sunday, May 11, 2003, at 11:34 Europe/Amsterdam, Just van Rossum wrote: > (Just yesterday I was working on some code where a (Cocoa) method > unexpectedly returned nil (translated to None in Python). I was > extremely happy to get a traceback instead of silent failure; since > None > is an actual object, it dispatches methods just like most other > objects, > ie. raise an exception if a method isn't found. A silent failure surely > would've cost me much more time to figure out what I did wrong. > Ignoring > messages to nil is convenient when you expect it, but it's a liability > when you don't. I much rather explicitly test for nil than shoot myself > in the foot.) This is the most important reason for not having a 'nil' object that behaves ignores all method calls. Implementing such an object is easy enough, but it is too easy to mis actual errors this way. And IIRC this feature doesn't even work perfectly in Objective-C (what if the method returns anything other than an 'id', like a float/double/struct). Ronald |