Dienstag, 6. März 2012

Clean Code #3: Beware optimization

This time I want to talk about optimization and what Clean Code Developers has to say about it. It relates to the KISS principle I talked about last time!

There are two rules which apply when thinking about optimization:
  1. Do not optimize
  2. No really, do not optimize

Why optimization is a waste of time

The reason for that is very simple: Most of the time you spend to much time on a topic which might be solved with a little money on extra hardware. Even worse, you may mess with your system architecture or produce code smell trying to sequeeze some extra milliseconds. Thereby you may introduce bugs, make it maybe harder to test the application or make it harder to understand/debug. All this is happening in the name of optimization in an era where we simply add some more ram or cpu power to our servers or another server to our cluster.

That said, don't be misguided by the simplicity the statement implies. Of course there are times when you need to optimize. When your web page takes 20 seconds to load there might be a problem which cannot be solved with adding more resources but with solving the underlying errors.
On the other hand, trying to make your website load faster when it loads on an average of 50ms might be a bit of the ground.

When you really really have to, stick to some simple rules:
  • Make sure you know exactly what to optimize (like: Maximum 1 sec. average loading time of webpage).
  • Stop when you achieved your goal. Don't go further until you really need it.
  • Aquire knowledge about where to start and really think everything through. Maybe the little bit extra performance can be achieved with simple methods.
If you know what you are doing and why you are doing it, there may be problems. But they may be worth the trouble. If you start headless and simply go for what is possible, you may not know when you are done and may make things worse. So set your goals right and follow them!

Keine Kommentare:

Kommentar veröffentlichen