Clean code because it’s fun

Adam Zerner
3 min readAug 28, 2017

--

Clean code takes time. It requires thinking, refactoring, code reviews, discussion, research, and sometimes even a rewrite.

Many project managers hate it when developers spend time on “clean code”. Where are the concrete results???

This is silly. Of course there are concrete results: increased velocity. With clean code, it takes less time to develop new features, make changes, fix bugs, and onboard new developers. These results may be realized over the long run rather than immediately, but that doesn’t mean they aren’t concrete.

Many project managers realize that there is a cost-benefit at play here, but unfortunately, they aren’t incentivized to care about the benefit. The person above them yelling in their ear often wants results NOW… “or else”. And for all they know, later on there may be a new project manager who will reap the rewards of the clean code investment he made in his team. You get the picture. Next time you label someone as stupid, consider that they may just not be incentivized to care about what you assume they care about.

Some project managers are competent and properly incentivized. They often think about how much time it’ll take to code cleanly versus the amount of time the clean code will save the team in the future. That’s great. But there’s something missing from that thought process: clean code is fun!

Fun leads to productivity

One reason why fun is good is because it leads to productivity.

Especially in cognitively demanding domains. Carrots and sticks may get someone to pull harder in tug-of-war, or it may get someone working in an assembly line to churn out more widgets, but it doesn’t work for cognitively demanding tasks. To motivate people who work in cognitively demanding domains, you need autonomy, mastery and purpose.

Clean code is related to all three.

  1. You’re giving the developer the autonomy to maintain the codebase the way they prefer.
  2. You’re allowing the developer to express mastery. Anyone can hack something together, it takes mastery to write clean and maintainable code.
  3. Many good developers find good code intrinsically satisfying, which I guess can be put under the umbrella of purpose.

Fun leads to easy hiring

Fun is good because it allows you to attract new talent, and retain current talent. This is incredibly important!

  1. Developers really do differ in productivity by an order of magnitude. Not 20 or 30%. 1000%! Yet, they differ in cost by only ~50%.
  2. Hiring and onboarding is very expensive, so it’s great if you can retain your developers instead of cycling through new ones.

Fun is fun!

I think this is the most important point. Writing shitty code makes me so angry. Writing good code makes me so happy. Every good developer I’ve met feels the same way. Writing good code is so much fun, and writing shitty code is so, so awful.

Let’s suppose that on balance, taking the time to write clean code actually reduces productivity by 20%. So what. What’s the big rush. Moving 20% more slowly is an incredibly small price to pay for a HUGE increase in happiness.

I suppose that sometimes you’re in an incredibly cutthroat situation where moving 20% more slowly would mean you’d be out of business. It seems unlikely to me, but it is possible. If so… why put yourself in such a position?

I suppose that sometimes you aren’t in charge, and your boss will fire you if you move 20% more slowly. If so, I think you should look for a new job. And I think that as a boss… why do this? So what if the bottom line is slightly smaller than it could have been. Doesn’t making people happy matter to you? Especially when the price of making your employees drastically happier is so small.

--

--

Adam Zerner

Rationality, effective altruism, startups, learning, writing, basketball, Curb Your Enthusiasm