False Optimization

So often I hear tech folks talking about some implementation as being better than another because “It is more efficient“.   Efficient?   Efficient for who?  The computer?  Are we shaving milliseconds off processing time?   That’s ridiculous.

We should be in the business of optimizing human time, not computer time.   Human time is more expensive – while computer time is cheap.

We want code to be laid out clearly and easy to read.  We want code to be like a poem.  We want something that we can maintain over time without having to scratch our heads every time we come back to.

A simple example, have a look at,

select
   id, process_date, qty
from
   usage
where
   coalesce(units, '') not in ('K1', 'K2', 'K3')
;

What the heck is that coalesce doing in the where clause? If you think about it for a minute it make sense.  Oh, it’s more efficient for the computer that way. Who cares?  How about

select
   id, process_date, qty
from
   usage
where
   units is not null and
   units not in in ('K1', 'K2', 'K3')
;

Here the where clause is immediately easy to understand and to maintain.  It speaks to the essence of the problem in clear pseudo English.

Leave a Reply

Your email address will not be published. Required fields are marked *