Scorn Globally, Act Locally

From Beautifulcode

Jump to: navigation, search

Scorn Globally, Act Locally is a philosophy put forward by [Alberto Savoia] in his article Beautiful Code in the Real World - Part II: Scorn Globally, Act Locally to address the problem of how to write beautiful code while working with ugly legacy code.

"Accept the job as a challenge. Accept that the code base is ugly; it’s OK – therapeutic even – to make fun of it and of the careless, incompetent, so-called-programmers who developed it. Accept the fact that you cannot single-handedly turn a huge steaming pile of legacy code into a thing of beauty. But be determined and committed to reject and eliminate ugliness in the bits of code that you do touch. In other words: scorn globally, act locally."
"The key to success in working with a pile of ugly code is to focus on small improvements. When you run into an ugly bit of code that you can or must change, make a conscious decision to make it more beautiful."

Here is some advice on how to act locally:

  • Write tests for a particular piece of code before you change it.
  • Refactor to reduce complexity and improve testability. Method extraction is a favorite; it’s fast, safe, and easy to revert.
  • Rename cryptic or ambiguous identifiers.
  • Delete. If you can identify dead, useless, or obsolete code, get rid of it.
Personal tools