Clean Code: Why it matters?

2023-05-09

If you've been coding for a while now, you probably have heard of and learned about:

  • KISS (Keep It Simple Stupid)
  • DRY (Don't Repeat Yourself),
  • YAGNI (You Aren't Gonna Need It) or
  • SOLID (tl;dw)

and other relevant acronyms you can think of.

Google

Like you, I love these terms and there were times when I was too attached to them. As an experienced developer, I've had my fair share of getting my hands dirty with these principles in action. I've learned how they can either be a friend or foe. However, in this blog post, I'll focus on why these guiding principles are essential rather than how to use them.

So, why clean code matters?

  • It fosters empathy. Empathy is the word that should be on top of every developer's list. When I code, I strive to balance delivering quality results with ensuring that it is something my colleagues and future self will appreciate. This is easier said than done, but in my experience, an empathic approach is more important than any other aspect of the subject being worked on.

  • Your code is your signature. As humans, we don't want to leave a bad impression of ourselves on others. From trivial things like indentation, spaces, new lines, and variable names to exception handling, unit tests, and other significant components of the codebase, they all say a lot about us as developers. What we do is as important as what we don't do.

  • Think about resilience and optimization. A house built on a weak foundation is set to collapse even before adversity strikes. That's the same with an application lacking a good codebase. I understand that an application's resiliency is not solely about clean code but its architecture as a whole. Still, let's not forget that good architecture starts with maintainable and readable code. On the other hand, I also recognize that developers tend to make upfront optimal code, and that's okay until we do too much of it. Most of the time, a significant amount of optimization is done when an application goes live in production. Having a good codebase from the beginning is one step ahead towards high-performing software.

My advice

  • If you belong to a team, seek for guidance before commiting your code. An authentic PR (peer's review) on a PR (pull request) goes a long way.
  • Stay curious. Growth comes from doing something wrong and making it right the next time anyway.
  • Internet is your friend. There are a lot of free and paid resources out there that can help you improve your coding skills. Pluralsight is a good starting point for quality materials.

The takeaway

It's good to keep these principles always in your pocket for reference, but don't let them drive you more than the requirements that add value to your customers as well as your teammates. Clean code's definition may vary depending on every team's perspective and conventions, the same reason why I gave emphasis more on the WHY and not the HOW.

More importantly, as Dave Gray mentions in his YouTube channel:

Keep striving for progress over perfection

Google

Later you'll find yourself writing excellent code and software in return.