Monday, September 27

Sticky Code

was working with though some legacy code when I discovered that the original coder had
  • avoided magic numbers by using Macros which was good
  • defined the Macros in multiple places which was bad
The Root Cause

I started asking myself "why" questions in order to discover the reasons behind this failure.

Question: Why has this duplication occurred?
Answer: The original location of the definition was poorly chosen and subsequent coders where reluctant to move the definition.

Question: Why were coders reluctant to move the definition?
Answer: Because to move code you need to delete it from its original location.

Question: Why are coders reluctant to delete code?
Answer: Either :-
  • they do not have source control
  • their source control software does not clean up after itself (files deleted in the repository are not delete in the workspace)
  • or they do not have decent code coverage.
The importance of moving definitions and implementation between different modules and libraries.
If code sticks to its original location and is not moved then over time you will find that you will get duplications or circular dependencies. Usually both.

No comments: