Mike Grouchy

  • Home
  • Posts
Mike Grouchy, June 26 2012

Write less code. 

One of the fundamental truths of software development is that you have to write code, but one of the biggest fallacies is the idea that writing code is your job. When I first started out as a software developer, I fell into that trap, writing code is a powerful thing, its empowering, you feel like you are productive and you are accomplishing things. However, what I have learned over the years is the real truth of the matter. The truth that the job of a software developer is to write as little code as possible.

Now, don't get me wrong, we should not be getting ourselves into code golf situations where we are compacting code and saving keystrokes to the point where the code you produce is no longer understandable. When you think about it though the fact that most of your time will be maintaining the terrible code you wrote, writing less code and not creating more work for yourself will start to look like an exceptionally good idea.


Look around, look at your tools, look at the framework you likely use to produce that thing you work on. Everything you do, all the tools you use, everything is trying make you write less code. Your tools are trying to make you less error prone, and abstracting away the things that will cause you trouble down the road.

So why should you write less code? When I said earlier that your job was to write less code, I was fibbing a little bit. Really your job is to think, your job is to think about the problem at hand, devise an elegant solution and then turn that solution into software. One of the byproducts of creating software is that you have to write code to solve problems.

Code is a by-product

Code isn't that important. We love to convince ourselves that it is because as we actually start executing and turning our solutions into software, it seems like writing code is both a means and an end unto itself. We talk about our editors, we talk about our language of choice and we talk about our environments. I do it, you do it, we all do it. There is no shame in enjoying the craft of the work you do. The trick is to stay focused. Code is awesome, but its also the enemy, it takes time to write, it can be fragile, it can be unclear and not particularly robust.

This is why I stick with the mantra "Write less code". Whenever I feel like something is getting bigger than it should be or more complicated than it should be, I say "Write less code". Whenever I write so much code that it gets hard to keep it in context, I refactor, I clean it up, all the while, thinking about "Write less code".

As much as it pains me to say, sometimes there is no way to get around writing a bunch of code, but if you can't be concise, be clear. Writing less code is writing clean code. Writing less code is also about writing clear code. When you are economical with the code you write the purpose of your code becomes clear.

So, whats the lesson here? Most importantly I think the lesson here is that code is a by-product, its an unavoidable thing that you generate in the process of doing your job. So think more, refactor more, remove some old code and write less new code, do yourself a favor and start this today.

Written by

Mike Grouchy

Previous Be Pythonic: __init__.py
Next Using Johnny Cache with Heroku and Memcachier