A directory of brand guidelines: logosearch.link

How to write legacy code

Dom Habersack
Dom HabersackMarch 25, 2020
The ruin of a house on an open field in front of a mountain.
It certainly didn’t look like this when I first wrote it.

“Legacy code” is what developers call code they do not want to work with. It is often old and difficult to change, because nobody knows exactly how it works anymore. Any small change can have unforeseen consequences that end up breaking something unrelated. These systems are expensive, because they slow down the development of new features.

A popular approach to fixing legacy code is a complete rewrite. We start rebuilding everything in a new system, keeping the old one around until we are done. In this rewrite, we promise to not make the same mistakes again.

It works great in the beginning. The new project is a blank canvas, free of the problems of the old code. Adding new features is fun and exciting. Until it isn’t.

All legacy systems used to be like that. Code does not start out terrible, and it does not go bad over night. Legacy code is caused by a lot of small decisions that all seem harmless at the time. These are some of these decisions that turn any project into legacy code:

  1. Stop writing tests. Developers can figure out what broke by remembering all areas they need to check.
  2. Use abbreviations everywhere. Everybody will know what “FBA” and “KAP” are, and how they relate to each other.
  3. Add a lot of one-time exceptions. Why are we building this new system, if we cannot make it do exactly what we want everywhere?
  4. Never collaborate with anyone. If they have questions, they can ask you (as long as you are still with the company).
  5. Never remove code you no longer use. Who knows, you might need it later.

What is another decision you have seen that slowly made one of your projects harder to work with?

– Dom

Continue reading

Write without fear. Edit without mercy.
#34April 29, 2020

Writing code for others to read

Clever code isn’t always the most readable. Especially when working in teams, readability has to come first.

Dollar bills positioned to look like a brain.
#30April 1, 2020

How to understand any codebase

Treat existing codebases as a blackbox. Take small pieces and write tests for them to understand a project’s inner workings step by step.

An analog alarm clock in front of a two-colored background.
#54September 16, 2020

End of an era

Moment.js is now a legacy project. While you can keep using it, these other projects might be better fits for you.

Read all issues →