Re: message to nil? (very basic question)
Re: message to nil? (very basic question)
- Subject: Re: message to nil? (very basic question)
- From: jgo <email@hidden>
- Date: Wed, 23 Jan 2002 16:26:17 -0800
>
> On Monday, 2002 January 21 at 06:36, Christophe Dore wrote:
>
> IMHO, the only problem with messaging nil is when nil in a
>
> variable is an unexpected value at that time.
>
>
Which can be a very big problem, indeed. In my experience, a variable
>
taking an unexpected nil value has cost many many hours of debugging...
>
Often, it crops up because some fundamental resource is unavailable...
>
> Java being unable to assert (until maybe 1.4, still in beta) those guys
>
> chose to disallow it.
>
>
I don't think that's the reason why the disallow it. Message-eating-nil
>
follows very much in Java's overall 'fail close to the defect' patterns
>
(strong typing, bounds checking, etc..). As well, there are other very
>
dynamic languages that do not allow messaging to nil; Python immediately
>
comes to mind and Python is significantly more dynamic than ObjC (and has
>
assertions).
Whoops, you lost me at the turn.
"Message-eating-nil follows very much... 'fail close to the defect'
patterns"!?! Just the opposite. It allows the program to coast
along for a time after the initial error has occurred, thus failing
farther away from the defect, which costs us many hours of debugging
to try to trace back.
It would seem to me that the lesson is that while sending a message
to a nil object itself creates no immediate problem, the programmer
should be aware that problems can occur in such places and defend
against it... and expect that we, ourselves, or others forget to
do so occasionally. It might be nice if there were some automagic
checks or reminders in the IDE, but...
John G. Otto, Eagle Scout, Knight, Cybernetic Praxeologist
Existence, Consciousness, Identity, Life, Liberty, Property, Privacy, Justice
<
http://gosc.nisus.com/~giovanni>