Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The term "clean code" is used to describe computer programming code that is concise, easy to understand, and expresses the programmer's intent clearly. Questions with this tag relate to the process of writing clean code, or refactoring old "dirty" code to be clean code.

While the idea of clean code has existed for many years, the term started to become popular in 2008 when Robert Cecil Martin (Uncle Bob) published his book Clean Code: a Handbook of Agile Software Craftsmanship.

Some of the primary ideas behind include, but are not limited to:

  • Ensuring that code has useful unit tests in place. This helps guarantee that code does what it says it does.

  • Keeping code units (classes, functions, et al) short and concise. A block of code should do one thing and do it well.

  • Eliminate frivolous comments. Code should be self-documenting through judicious selection of names for code elements (classes, functions, variables, et al).

  • Refactor early, refactor often. Just like a manuscript goes through many revisions, code should not be written once. As new code is added, old code needs to adapt as new structures take form and code is reused.

history | excerpt history