19 Jun 2012. comments
Software should be maintainable but it should also be performant. Which is more important? Well as it turns out in order to optimize software for performance it must be maintainable. Ease of change can easily be the most important factor in making something run well.
Premature optimization often hinders evolution because it’s designed to address a very specific imagined concern now without regard for future concerns unrelated to performance. This is not to say that optimization is not important it’s just something that should be done as-needed. Developing 90% of the functionality now and shipping it quickly is better than 100% of it shipped late or never. The simple truth is that you don’t know what will be needed down the road, so developing/optimizing for it early will be a waste of time. Often times it turns out the code you prematurely wrote wasn’t needed or your assumptions were wrong. So not only will you not need it, but even if you do it won’t be in the right form that you anticipate today.
Today’s compilers are also a lot smarter today than you are and can perform lots of optimizations themselves. Sometimes an optimization you think will help has already been dealt with by your compiler or environment, so it’s important to not optimize until you’ve actually proven via measurement where and why a performance issue occurs.
Its far more important to write code that is easy to understand and optimizations tend to be difficult to understand. Writing code that is clear and explicit is better than writing clever code. Programmers are really expensive and so it’s to your benefit to write code that optimizes for their time and not a computer.
“Programs must be written for people to read, and only incidentally for machines to execute.”
– Harold Abelson