Clean Code

Clean Code

Symptoms of Poor Design

Code smell, also known as a bad smell, in computer programming code, refers to any symptom in the source code of a program that possibly indicates a deeper problem. According to Martin Fowler,[2] "a code smell is a surface indication that usually corresponds to a deeper problem in the system".

"smells are certain structures in the code that indicate violation of fundamental design principles and negatively impact design quality"

these smells are:

  1. Rigidity
  2. Fragility
  3. Immobility
  4. Viscosity
  5. Needless complexity
  6. Needless repetition
  7. Opacity 

Rigidity

The design is hard to change

  • changes propagate via dependencies to other modules other modules
  • no continuity in the code
  • Management reluctance to change anything becomes the policy

Telltale sign: ‘Huh, it was a lot more complicated than I thought.’ 

Fragility

The design is easy to break

  • changes cause cascading effects to many places places
  • the code breaks in unexpected places that have no conceptual relationship with the changed area.
  • fixing the problems causes new problems

Telltale signs Telltale signs

  • some modules are constantly on the bug list
  • time is used finding bugs, not fixing them
  • programmers are reluctant to change anything in the code 

Immobility

The design is hard to reuse

  • the code is so tangled that it is impossible to reuse anything impossible to reuse anything

Telltale sign: a module could be reused but the effort and risk of reused of separating it from the original the original environment is too high.

Viscosity

Viscosity of the software

  • changes or additions are easier to implement by doing the wrong thing

Viscosity of the environment

  • the development environment is slow and inefficient
  • high compile times, long feedback time in testing, laborious integration in a multi laborious integration in a multi-team project team project

Telltale signs

  • when a change is needed, you are tempted to hack rather than to preserve the original design
  • you are reluctant to execute a fast feedback loop and instead tend to code larger pieces

Needless Complexity

Design contains elements that are not currently useful currently useful

  • too much anticipation of future needs
  • developers try to protect themselves against probable future changes
  • agile principles state that you should never anticipate future needs

Extra complexity is needed only when designing an application framework or customizable component

Telltale sign: investing in uncertainty

Needless Repetition

The same code appears over and over again, in slightly different forms

  • developers are missing an abstraction
  • bugs found in a repeating unit have to be fixed in every repetition

Telltale sign: overuse of cut-and-paste 

Opacity

The tendency of a module to become more difficult to understand

  • every module gets more opaque over time
  • a constant effort is needed to keep the code readable easy to understand and communicates its design

Telltale sign: you are reluctant to fix somebody else’s code – or even your own! 

To view or add a comment, sign in

Explore content categories