Vlad's Roam Garden

Powered by 🌱Roam Garden

functions should be small

I believe the easiest way to understand why this is important is by considering functions that don't follow this rule.

Large functions are confusing, as they force you to be aware of a lot of things (violating reduce the number of things you need to be aware of to understand any given code block)

Large functions tend to mix code at the multitude level of abstraction ([[all code in the function should be at the same level of abstraction]])

You'd often straggle to give them a clear name. Function defines a concept in a language that you are creating. If your function is too large and it's doing too many things - you can't give it a name that would sharply define the concept. Making your language less expressive.

[[functions should do one thing]]

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.