We all aspire to write readable code. Being experienced programmers, we have a good grasp of how to do it. Or so I thought. However, I first really un

How to write Readable Code? Beyond the Obvious

submited by
Style Pass
2025-01-02 16:30:05

We all aspire to write readable code. Being experienced programmers, we have a good grasp of how to do it. Or so I thought. However, I first really understood what readable code means when I listened to Venkat Subramaniam’s following talk years back ( look at the next five minutes in the above talk).

As the video explained, when someone asks what you did at the weekend, he is not asking for everything you did, but rather looking for a high-level statement like we stayed at home, visited parents, or went on a trip. They would ask follow-up questions if they wanted to know more about a specific part.

Our code is composed of procedures — an entry procedure that calls subprocedures, subprocedures that call the next level, and so on. Each procedure implements an algorithm.

In a readable code, the entry procedure should show the high-level algorithm, demonstrating the overall algorithm while hiding details that do not affect the high-level understanding. This demonstration is done by leaving clues about what it does in the code via variable names, procedure names, comments, and logic you write at that level. It is an art to leave enough breadcrumbs but not too much that will create clutter. Then, each sub-procedure should show its algorithm while hiding details that do not affect that procedure-level understanding.

Leave a Comment