Thursday, March 09, 2006

CODING TENET: Don't be clever

CODING TENET: Don't be clever unless you have to be.

By clever here I mean "code that is hard to understand at first glance". Such code is harder and more costly to maintain, so think long and hard about when you want to put forth that kind of effort in the future before you insert your whiz bang implementation of string searching.

I've met plenty of developers who think it is great to make brain-damaging clever optimazations of code where it makes absolutely no difference. For example, lets say we updating the GUI of our application. From a programmer's perspective, the GUI is INCREDIBILY slow. Humans can't see much below 30 frames a second, which means that, in terms of your interface taking 1 millisecond or 300 millisecond LOOKS EXACTLY THE SAME to the user. I'll repeat my point: Don't be clever when you don't have to be.

The same holds true for all those really fancy algorithms you learns about in CS. The reality is that for small numbers of elements (in the hundreds lets say), doing the brain dead stupid bubble sort or linear search is just fine. Sure it is O(N^2), but the user can't tell. Don't be clever when you don't have to be.


Post a Comment

Links to this post:

Create a Link

<< Home