Simplicity Comes from Reduction
Paul W. Homer.
"Do IT AGAIN ...," My boss told me as his finger pressed hard on the Delete key. I watched the computer screen with a all-too-familiar sinking feeling, as my code-line after line-disappeared into Oblivi On.
My boss, Stefan, wasn ' t always the most vocal of people, but he knew bad code when he saw it. And he knew exactly.
I had arrived in my present position as a student programmer with lots of energy and plenty of enthusiasm but absolutely n o Idea how to code. I had this horrible tendency to think, the solution to every problem is to add in another variable some place. Or throw in another line. Instead of the logic getting better with each revision, my code gradually got larger, more complex, and Furt She away from working consistently.
It ' s natural, particularly when you ' re in a rush, to just want to make the most minimal changes to an existing block of CO De, even if it is awful. Most pro-grammers would preserve bad code, fearing that starting anew would require sig-nificantly more effort than just G Oing back to the beginning. That can being true for code that's close to working, but there was just some code that's beyond all help.
?? Things every Programmer should Know
?
??????????????? 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 the one should easily toss away all of the that typing, naming, and formatting. My boss's reaction was extreme and it did force me to rethink the code on the second (or occasionally third) attempt. Still, the best approach-fixing bad code is-to-flip into a mode where the code is mercilessly refactored, shifted Aroun D, or deleted.
The code should is simple. There should is 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 is just enough to get the job done, completing the algorithm or performing the Calculati Ons. Anything and everything else is just extra, unwanted noise, introduced accidentally, obscuring the flow, and hiding the IM Portant stuff.
Of course, if that doesn ' t does it, then just delete it all and the type it in over again. Drawing from one's memory in the that's the can often help cut through a lot of unnecessarily clutter.
Simplicity Comes from Reduction