July 15, 2006

Overcautious Coding

Filed under: commons

Michael Feathers illustrates nicely the problem of overcautious coding. The following should probably be coding principles:

Spurious null checks are a symptom of bad code.

The reactive thing whenever there is a core dump or crash because of nulls or empty pointers is to add a check of null and wash your hands off it. The right thing would be to find out origin of the null and try to avoid it as much as possible. It is not only that the if can cause performance loss, it can inadvertently cover up the malicious code that generates the null.

It is also easier to program to an interface where the callee does not throw nulls so that the multiple callers don’t have to check for them.

Tags: , , .

Comments »

Trackback    RSS feed for comments on this post.

No comments yet.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Creative Commons License Copyright © Abhijit Nadgouda. Hosted on Blogsome, powered by Wordpress