Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

FWIW, I use Null Objects to eliminate null checks. Makes recursion (tree climbing) more concise, legible.

Bonus: Java's HotSpot magick will NOP (most?) methods of Null Objects, making this a zero cost abstraction.

I should probably write a concrete example for a blog or something.

TLDR: For every base class such as TreeNode, create a NullTreeNode that does nothing, then replace all uses of null with NullTreeNode. Voilá, no more null checks or NPEs.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: