3 ms·
> Every time we extract a chunk of code from a larger function into a smaller more encapsulated one, the code becomes just a little bit harder to follow. I, in
by jwalton 6y ago
> Every time we extract a chunk of code from a larger function into a smaller more encapsulated one, the code becomes just a little bit harder to follow.
I, in most cases, disagree with this. If this were true, I suspect the best and easiest to understand functions would be thousands of lines long
Often you write functions that only get called from one place, just so you can give a name to a block of code and make it easier to understand.
Just today, for example, I wrote a big case/switch statement to figure out the URL for a user on a system where the URL is different depending on where the user exists in a hierarchy (I didn’t write the server side of this - gotta work with what I have). I extracted this all out into a “getUserUrl()” function. In the caller, it’s much easier to understand what is going on when you see “getUserUrl()” than it would have been if there was the giant switch statement there.
Cognitive burden would generally not be improved by inclining every function I call.