Tuesday, December 03, 2013

Null: The Billion Dollar Mistake

Null References: The Billion Dollar Mistake: @ InfoQ
"Tony Hoare introduced Null references in ALGOL W back in 1965 “simply because it was so easy to implement”, says Mr. Hoare. He talks about that decision considering it “my billion-dollar mistake”."

Sir Charles Antony Richard Hoare, commonly known as Tony Hoare, is a British computer scientist, probably best known for the development in 1960, at age 26, of Quicksort.
He currently works in Microsoft.


In object-oriented computer programming, a Null Object is an object with defined neutral ("null") behavior. The Null Object design pattern describes the uses of such objects and their behavior (or lack thereof).

interface IAnimal {
    void MakeSound();
}
class NullAnimal : IAnimal {
    public void MakeSound() {
        // Purposefully provides no behaviour.
    }
}
...
IAnimal unknown = new NullAnimal(); //instead of: unknown = null;
   unknown.MakeSound(); // outputs nothing, but does not throw a runtime exception  

No comments: