Software Development with Linux

No to premature optimization

MON, 01 AUG 2011

Thanks to Kent Beck for sharing  Harold's Corollary To Knuth's Law.  Donald Knuth wrote, in Structured Programming with go to Statements : "Premature optimization is the root of all evil".

While Mr. Knuth was discussing development, Harold argue that the same is true with testing; one should not do premature tests optimization or discard some tests that are thought to be too resource hungry.

Even if the veracity of those statements seems evident, some developers (in the widest possible sense) still do not understand it.  It has been showed many times that optimizations without measurement increases the risk while the gain you may have is only attributable to chance.

One easy way to keep you from doing premature optimization is to stick with to Simplicity rule : "Always do the simplest thing that could possibly work."  This should not be confused with the 1st Law of Simplicity.  I mean, you do not want to start simplifying things that you already have.  Instead, you want to create something new and you want to do the simplest thing; that is often the first thing that comes to mind.

This is similar to prototyping, where you start with the first thing that works.  Once it works, you are able to measure anything you want, and improve what needs to be improved.  You should expect your first iteration to fails.  But thanks to measurement, you will be able to optimize where appropriate and reach the best solution quickly, without wasting time where there is nothing to gain.

Please, join this campaign and share this with the (software development) world : "Say no to premature optimization!"