Hacker News new | ask | show | jobs
by apelapan 899 days ago
Long functions are not hard to grok, if they have a logical flow and stay reasonably close to a common level of abstraction (which can be high or low, doesn't matter). You just read top to bottom and follow the story.

20 files with 20 functions each does not cause high cognitive load, if the scope of each file and each function makes sense. You easily find the file+function you need, whenever you need to look something up and the rest of the time it is as if the rest didn't exist.

Good code can come in any shape. It is not shape itself that is important, it is the "goodness" that is important.

2 comments

Yep. Long functions can be easier to read and simpler to follow than multiple methods, if they're well documented.

Carmack has a good essay about it.

http://number-none.com/blow/john_carmack_on_inlined_code.htm...

My heuristic is that if logic is repeated at least 3 times, it's good to pull out into its own function, and even then you still need to consider liskov substitution principle.