Vlad's Roam Garden

Powered by 🌱Roam Garden

readability can be understood in computational terms

People often argue about code readability. Some say it's subjective and there is certainly a degree of truth in that. But at the same time there is a large set of "best practices" out there that most engineers can agree on.

Which implies that there is some underlying objective factor we think of when we're talking about readability.

Here I propose a framework of thinking about it from the computational perspective. It explores computational effort required to understand a given code snippet and how common best practices tend to reduce it.

Computational perspective can serve as objective way to define readability.

modelling is part of understanding. if the code you see is misleading and causes you to build incomplete models

Referenced in

functions should be small

From the computational perspective this harmonizes with the idea of executing the tree search on the code you're reading. As it moves code in a direction that would minimize the amount of linear search we are required to perform at any given node.

Use Long Names for Long Scopes

In computational terms - the name of the entity is the key you'd use to find it within its scope. If the scope is small - a shorter name is sufficient to identify the entity unambiguously. With the larger scope - you have a large number of elements, and so the entity name needs to contain more information.