Re: [Pyobjc-dev] Calling methods on nil
Brought to you by:
ronaldoussoren
From: Dinu G. <gh...@da...> - 2003-05-11 14:41:20
|
bb...@ma...: > Over the last-- jeez, nearly 15 years-- I have seen novice and > experienced developers-- myself included-- waste many many hours > trying to track down a problem that turned out to be an unexpected > nil. Going with a 'message to nil raises' model may have required > the addition of quite a few extra if () statements here and there over > the years, but that route would have considerably decreased the > frustration factor for quite a large number of developers. While one can surely argue about the value of "messages to nil being eaten or not", I think all OO purists will agree that checking for the type of an object (which here includes: comparing to nil/None) is a very bad idea! You save lots of if-statements if you can dele- gate your decission-making to the message dispatching mechanism. Nil is just another singleton value to compare with (like null poin- ters in C). So, sometimes it might just suffice for it to "eat your messages", but to obtain clean code you more often want to have a single but special value of some class which behaves differently in *some* respect (leaves in trees, etc.). This is where the "Null" pattern comes in, because you can also use it as a subclass of your "real" representation (class). See my original link for further info. If you use a Null object that way you won't have the kind of trouble that you and Just are citing, because you have only "regular" objects and (mostly) one special case object. I guess, the creators of ObjC just were trying to help people using nil like this. But as I said, it won't always be enough to "eat everything." Regards, Dinu -- Dinu C. Gherman ...................................................................... "I want to put a ding in the universe." (Steve Jobs) |