Functions
Functions should do one thing. They should do it well. They should do it only.
— Robert C.Martin
Small!
Functions should
-
be small.
-
be smaller than that.
-
contain no indentation whose level is greater than two.
Do One Thing
Describe steps instead of things.
But how?
One Level of Abstraction per Function
Use The Stepdown Rule.
The Stepdown Rule
Read the program as a set of TO paragraphs.
For example,
A function should contain no TO paragraph deeper than two levels.
Refactor the example above to