3 ms·
Function shortness is not, in and of itself, a value. There are many obvious examples where it makes excellent sense to refactor a complex function into severa
by peteforde 4y ago
Function shortness is not, in and of itself, a value.
There are many obvious examples where it makes excellent sense to refactor a complex function into several smaller functions. I get frustrated with the spirit of this post because I honestly have never seen anyone challenge this.
However, I frequently see PRs which appear to be breaking a longer but repetitive function into a large number of mostly single line functions, apparently with the single goal of achieving checklist compliance with the folk wisdom. In these cases, we've devolved from a list of (for example) simple name mappings with the occasional downcase() (for the bold!) to having to jump back and forth between multiple points in the file, which has now grown by 80-150% to account for all of the begin/end sigils (language/lint dependent).
If you're converting a JSON string to a dictionary and then mapping a large number of attributes, moving from
object.foo = json["foo"]
to
object.foo = extractFoo(json)
with a matching three line getter you have to scroll 2-3 pages down to read and does the exact same thing is not a win.
TL;DR context matters and general rules only help when you don't treat them like hammers.