Code Clarity

Code clarity is the ability to easily understand what code does.

Clarity is the single most important issue when writing code.Inevitably code to increase performance degrades from code clarity. Speed, size and memory usage are all secondary. After the code is written and functional measure performance and those areas that show performance deficits are to be addressed at that time.

In general performance decisions made when writing the code are almost always in the wrong places. Code clarity suffers and overall performance is not improved.

Here are a couple of examples I was involved in:

I have seen input routines for a teletype that runs at 110 baud optimized saving a couple of microseconds per character, less than a 0.002% savings in CPU cycles and 0% overall performance improvement and there was more code to try and understand. OK, I admit I did that—in the first week I was programming computers. What a waste of time and code clarity.

Years later we wrote a unix meta-port and after getting it to run it was slow. We were at a loss to understand why the performance was so bad. After a few attempts that did not improve things I wrote a performance monitor. What we found was that 90% of the CPU time was spend in memcpy()—who would have thought of that. Using the performance monitor we were able to reduce the CPU usage of memcpy() to 10%. This was only possible with performance measurement. All the time we had put into optimizing the other areas OS was basically wasted time and we did not optimize the one most significant area.

Write for clarity then measure and optimize the actual performance bottlenecks.

About zaph

Long term Mac/iOS & Cocoa developer.
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply