null Sucks: A Case in Point

Posted by: Robert Fischer on 2009-10-17 14:30:00.0

Take a look at this API: ClassNode#addProperty. Turns out that if you pass null into getterBlock and setterBlock, you get the default implementations. Maybe1. Normally passing null around blows up in unhelpful ways, but here null is a useful value. How is a programmer to know?

I’m increasingly convinced that immutability2 and strong type systems in languages aren’t just about concurrency or letting the computer optimize or catching bad code early. Increasingly, I’m convinced that the key value they provide is clear, meaningful, and maintainable code. Which is really the key problem in software development these days, isn’t it?

1 As of this writing, it’s an outstanding question if the compile phase of the AST transformation impacts whether or not the null values are translated: mailing list conversation.
2 See this nice presentation from Rich Hickey, author of Clojure.


Creative Commons License
This article was a post on the EnfranchisedMind blog. EnfranchisedMind Blog by Robert Fischer, Brian Hurt, and Other Authors is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.

(Digital Fingerprint: bcecb67d74ab248f06f068724220e340 (75.74.236.77) )


be the first to rate this blog


About Robert Fischer

Robert Fischer is a multi-language open source developer currently specializing in Groovy in Grails. In the past, his specialties have been in Perl, Java, Ruby, and OCaml. In the future, his specialty will probably be F# or (preferably) a functional JVM language like Scala or Clojure.

Robert is the author of Grails Persistence in GORM and GSQL, a regular contributor to GroovyMag and JSMag, the founder of the JConch Java concurrency library, and the author/maintainer of Liquibase-DSL and the Autobase database migration plugin for Grails.