by Lyren · 8y ago · 0 comments
We don't always hold ourselves to it, sometimes 5-6 line functions make sense, but we strive toward 4. Sometimes it's as easy as breaking code out into a new function, but sometimes you just simply have to create a class for it. That way a lot of complicated code suddenly becomes very easy without much effort.
Limiting function length to < 10 lines is like limiting your walking stride to 30cm. You'll spend most of your time chasing useless functions when trying to understand the system.
Of course we don't count every bracket or blank lines. Only the rows with any logic or assignment.
And yes, I agree, there are occasions where the complexity goes up. If there is a good argument for that, then we of course go with it.
But so far, almost everything anyone in our team has made, has been improved by rewriting it to something that works well in 4 lines, be it using polymorphism, object oriented, or functional.