Overcautious Coding

This post has already been published on code::gallery blog which now has been merged into this blog.

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-endif 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.

Technorati tags: ,

Copyright Abhijit Nadgouda.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: