From Alex Molas
Good code is rarely read
The other day, I was interviewing a developer for a position at Wallapop. The candidate was a bit junior, but I enjoyed their technical assignment, and the conversation was going great. One of the questions I had to ask was
How do you define good code?
I was expecting an answer in the lines of “best practices, DRY, SOLID, code formatting, design patterns, etc.”, but the candidate just answered.
Good code is code that’s easy to read.
And this apparently simple answer got me thinking for the last week. Here are some random thoughts I had.
Why best practices?
Best practices are tools that help us write code that’s easy to read. These practices, such as the DRY principle, following SOLID, and maintaining consistent code formatting, are not arbitrary rules. These guidelines have been developed to ensure that code is understandable and maintainable. When code is easy to read, it’s easier to debug, extend, and refactor. This readability allows other developers (or even your future self) to quickly grasp the logic and purpose of the code without extensive documentation.
Read to write
But no one reads code just for the fun of it 1. When you read code, it’s to understand it and then use it. This means that the purpose of code readability is to facilitate further development. If code is written clearly, it reduces the cognitive load on the developer who will work with it. Code that is easy to read is also code that is easy to use. When functions and classes are named appropriately and their purposes are clear, you can use them without understanding their internal workings.
Code shouldn’t be read more than written
The saying “code is read more than written” is often cited to emphasize the importance of writing readable code. But it could be a symptom of bad code. If a code needs to be read frequently, it might indicate that it is not as clear or intuitive as it should be. Good code should be used more than read. It should be so well-designed that developers can use it without needing to read through it extensively.
Good code is rarely read
Therefore, your goal when writing code is for it to be read as little as possible. This might sound counterintuitive, but if your code is so easy to use that it doesn’t require an in-depth undertanding to be used, then it is good code. It should be so well-structured and named that its purpose and functionality are immediately apparent. This minimizes the need for others to read through and interpret the code, allowing them to use it more effectively.
In conclusion, good code is rarely read. Good code is so ergonomic that you almost don’t need to read it; you just use it. It allows developers to focus on building features and solving problems rather than deciphering existing code. This is the ultimate goal of good coding practices: to create code that is so clear and intuitive that it almost disappears, allowing the functionality to shine through.
No comments:
Post a Comment