Hacker News new | ask | show | jobs
by Lyren 2835 days ago
I can vouch for Clean Coder. We watched them in our company. It's a small dev team so we took the time together. Afterwards we implemented a 4-line rule amongst other things.

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.

2 comments

And this is why I don't like the clean code series and usually recommend against reading it.

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.

This honestly sounds extremely limiting. I do get why you'd want to make functions short in general but I think there's a tipping point where making the functions shorter actually increases overall complexity and 4 lines seems to be past that tipping point in my experience.
It's honestly not as limiting as you might think. Readability has definitely improved a ton since switching.

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.