Blog

Empathy – The Key to Great Code

23 Jan, 2024
Xebia Background Header Wave

Which qualities in a person lead to great code?

I used to think it was raw intellect, technical know-how, or breadth of knowledge. Slowly but surely, this sentiment faded, and my opinion shifted. Nowadays, I believe the key to great code is empathy.

Empathy the key to great code? What’s this guy talking about?

Allow me to explain.
I’ll start with a quote from Kent Beck that has stuck with me ever since I first encountered it:

Software design is an exercise in human relationships

The more experience I gain and situations I encounter, the more this statement resonates with me.

Why?

Human relationships are all about communication, and although some might disagree, so is code. Code automates tasks, yes, but it is also a means of communication – it just happens to be executable.

Communication becomes increasingly important as projects get more complex or more people get involved. This might be why many definitions of what makes code "good" center around readability.

Remember, our code is executed by a computer but read by fellow humans.

Consequently, we can ask ourselves the question: how do we create readable code? Entire books have been written on the subject. Notable titles such as Clean Code, The Art of Readable Code, and The Programmer’s Brain helped me tremendously in this regard. Take their key takeaways, zoom out, and you start to see empathy.

Empathy, the ability to understand and share the feelings of another, will help put yourself in the shoes of future readers of your code.

Next time you’re sitting down to code, pause. Take the freshly written line of code before you and ask yourself questions such as:

  • How would another interpret this code?
  • Would this code make sense to them?
  • How can I help them understand this code?

Heed the answers to these questions, and you will invariably end with great code. Better yet, sit down and work together on code! The questions will turn into a conversation instead of an internal dialogue.

These days, I don’t follow hard rules like "never write comments" or "never put more than three lines of code in if/else branches" anymore. Instead, I draw on the innate human quality of empathy precisely because of its broad applicability. It is my moral compass for code.

Using empathy to get to great code. An exercise in human relationships indeed.

Roy Straub
Passionate about Software Craftsmanship. Interested in subjects such as Clean Code, Domain Driven Design and Extreme Programming. Happily coding since 2010.
Questions?

Get in touch with us to learn more about the subject and related solutions

Explore related posts