97 Things Every Programmer Should Know

(Chris Devlin) #1

Collective Wisdom from the Experts 151


More time gets wasted in trying to salvage bad work than it should. Once
something becomes a resource sink, it needs to be discarded. Quickly.


Not that one should easily toss away all of that typing, naming, and formatting.
My boss’s reaction was extreme, but it did force me to rethink the code on the
second (or occasionally third) attempt. Still, the best approach to fixing bad
code is to flip into a mode where the code is mercilessly refactored, shifted
around, or deleted.


The code should be simple. There should be a minimal number of variables,
functions, declarations, and other syntactic language necessities. Extra lines,
extra variables...extra anything, really, should be purged immediately. What’s
there, what’s left, should be just enough to get the job done, completing the
algorithm or performing the calculations. Anything and everything else is just
extra, unwanted noise, introduced accidentally, obscuring the flow, and hiding
the important stuff.


Of course, if that doesn’t do it, then just delete it all and type it in over again.
Drawing from one’s memory in that way can often help cut through a lot of
unnecessarily clutter.

Free download pdf