Empathy With Legacy Code

Asim Husanović
EQS Engineering Blog
6 min readOct 6, 2022
Source: https://assets.asana.biz/transform/8755b248-aa09-429f-88ab-1664f31c4ce5/article-leadership-empathy-map-template-2x

TL;DR

Empathy with legacy code is important because:

  • It can help developers better understand the code and make modifications as needed.
  • It is vital for developers to understand how users interact with their software and how they feel about its usage.
  • It can help developers put themselves in the users’ shoes and determine their needs and desires.
  • Empathy is particularly important when developers need to work with legacy products because this can be a difficult and frustrating experience.

To have empathy with legacy code, developers should:

  • Understand the purpose of the code.
  • Understand the structure of the code.
  • Write unit tests for the code.

Motivation for This Article

The primary motivation of this text is to serve as an introductory guide for developers who need to work with legacy (existing) code. It is also intended to serve as a reminder for experienced developers who may have forgotten certain bases.

Hopefully, this text will help developers to have more success in their work with legacy (existing) code.

Introduction

Empathy is the ability to comprehend and share someone else’s feelings. It is a fundamental human quality that allows us to be compassionate and connect with others. When we empathize with someone, we can look at the world from their point of view and understand their feelings. Empathy is a critical part of our social cognition and plays a role in our capacity to connect and communicate with others. Empathy is a complex emotion that may be difficult to define, but it is usually seen as a positive emotion that helps us feel connected to others.

Source: https://pxhere.com/de/photo/1093445

A legacy is something that is passed on generation after generation. This may be a physical object, such as a piece of jewelry, or something more intangible, such as a family tradition. In the IT world, the word “legacy” can also refer to any outdated hardware or software that is still in use.

Legacy code is the code that the original developers do not maintain anymore. It is often written in an out-of-date programming language or on an unsupported platform. Moreover, the existing code is hard to understand, modify or even extend and newly written code does not have automated tests or documentation.

Empathy with legacy is the ability to understand and share the sentiments of those who came before us. This is about being able to see the world through their eyes and understand their experiences.

Empathy with legacy code is the ability to understand and work with code written by another individual. It is essential to empathize with the inherited code, as it can be challenging to read and understand the code you have not produced. Empathy with the existing code can help you to understand and modify it if necessary.

Empathy is essential for developers because it allows them to understand how users interact with their software and how they feel about using it. It also helps developers put themselves in the place of users and understand their needs and wants. Empathy is particularly important when developers need to work with existing products, as this can be a challenging and frustrating experience. However, by having compassion for the legacy products, developers can hope to create new products that are compatible with them.

Here are a few tricks we need to do to be better at building new projects based on legacy code or refactoring legacy code.

Purpose, Structure, Testing, and Verification

It is crucial to understand the purpose of legacy code to fully understand the programmers who wrote the code at the time, with the available technologies.

Another thing is to understand the structure of the code.

And the third is optional but very important. If possible, write unit tests for legacy code.

Refactoring code may be a very satisfactory experience for developers. Once they have a functioning system, they can finally take the time to redesign it and write it the way they think it should be. This is because, during the development of applications, there are still time constraints, new features, etc., that can prevent developers from following their own rules and coding principles.

When developers work with code written by someone else, it is essential that they first understand the purpose of the code. Once the purpose is understood, the programmer has greater capacity and opportunity to understand the structure of the code better. This may be difficult if the code is written in an outdated programming language or utilizes outdated principles. In these cases, writing unit tests can help validate assumptions on the functioning of the code.

Easy To Say (but So Difficult To Do)

Practice and theory are different. Although code refactoring is often written and talked about (in textbooks, books, and conferences), it is much more difficult to refactor code in practice.

We often come across how to understand the purpose of the code, its structure, or how to write unit tests in speeches. How to put it into practice is much more challenging.

Below we give examples that will help you understand the theory and the actual practice.

source: https://steemit.com/quotes/@kingcoc/a-phrase-that-s-easy-to-say-but-a-hard-thing-to-do-when-you-re-broken

Understanding Purpose

When documentation or code does not have comments to explain the purpose of particular methods, classes, parameters, or return values, another tactic should be taken.

First, find the people who wrote the code. If they do not exist, try to find people who participated in the software design, based on which the purpose of the functionality can be determined. If there are no such people, try to find people who use the software. In that case, they can be beneficial. Even more, sometimes they can say much more than the programmers themselves (who probably forgot why they wrote code long ago) because they know how the program works, its shortcomings, what errors it has, and the like.

source: https://commons.wikimedia.org/wiki/File:Business_presentation_byVectorOpenStock.jpg

After the meeting, you should be able to answer the following questions:

  1. Which problem does the software resolve exactly?
  2. What are the expected inputs, and what are the outputs of a given feature? It is essential to be aware of the limits and restrictions!
  3. Which are the dependencies of certain features? Is there any precise sequence of actions?

Understanding Structure

To understand the general structure of the legacy code, it is necessary to be able to answer the following questions:

  1. Identify the entry point of the code. This is typically the main function.
  2. Identify the dependencies of the code. These are the libraries that the code uses.

To understand a particular code, it is necessary to be able to do the following:

  1. Identify the purpose of the observed code.
  2. Understand the code flow.
  3. Analyze the code behavior.
  4. Understand the code dependencies.

Advice:

When you have drawn the schematics, diagrams, and workflows, arrange another meeting with the abovementioned people. Do not make your presentation too technical if there are no technical people at the conference; this will help you to identify any mistakes you may have made in your understanding of the purpose and functionality.

Unit Tests (Optional)

If a project has a code freeze, making changes or writing unit tests may not be possible. However, if this is not the case, writing a few unit tests can help ensure that your understanding of the code is correct. You don’t need to write unit tests for every aspect of the code, but a few critical tests can help ensure accuracy.

Why?

Before embarking on the adventure of refactoring legacy code, it is essential to ask yourself WHY it should be done. Is there an actual purpose?

After answering this question, or perhaps better yet, following the iterative questioning technique used to investigate cause and effect relationships — the five WHYs, it is essential to ask yourself the question HOW?

If you can answer 5 WHYs and one HOW it shouldn’t be a problem to answer the question WHO?

Source: flickr.com

Conclusion

Understanding and sharing the feelings of those who wrote the code allows developers to understand the code better and make the necessary changes. Empathy can help developers position themselves as users and understand their needs and desires.

Does your heart beat for developing exciting SaaS products? We are always looking for motivated new team members. Take a look at our vacancies: https://eqs-group.personio.de/recruiting/positions

--

--

Asim Husanović
EQS Engineering Blog

An incurable optimist, a lover of science, technology, progress, sociology, psychology, history, and much more.