Null references

Regan Heath regan at netmail.co.nz
Tue Aug 21 04:55:58 PDT 2012


On Tue, 21 Aug 2012 12:32:31 +0100, bearophile <bearophileHUGS at lycos.com>  
wrote:

> The very good Mark C. Chu-Carroll has written a little blog post about  
> the lack of null-related errors in his Scala code:
>
> http://scientopia.org/blogs/goodmath/2012/08/20/nulls/

It's prob no obvious from my other reply, but you might have guessed, I'm  
of the opinion that Otaku, Cedric's blog post is spot on and Mark C is  
wrong.  Well, not wrong exactly but not right either.

A Null pointer exception in Java will give you a stack trace, meaning you  
can be sure which method triggered it, meaning you don't have to examine  
"everything", just those method calls/objects used therein.

If your method is so large that this is a daunting task, then you're  
already doing something wrong.

Plus, I don't buy the argument that having to explicitly type ".get" will  
stop anyone from automatically coding statements like:

val g: Option[T] = f.doSomething()
g.get.doSomethingElse()

and suffering the exact same null pointer exception/error despite using  
Option and boxing into a Not-Null type.

Like checked exceptions people will simply ignore the possibility of error  
and type the above anyway.  So, end result, it's just more typing for no  
real gain.

On the other hand, the suggested syntax of "bob?.department?.head?.name"  
 from Kotlin is pure genius, and has a good chance of actually being used.

R

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the Digitalmars-d mailing list