The Hungry Programmer

Published on January 09, 2012 by Jesse Storimer

Programming is a lot like eating.

Tonight I was hungry. I wasn't at home. I couldn't go to the kitchen for a snack. I looked around and saw only McDonald's across the street.

Then I was struck with the same dilemma that I face whenever I leave the comfort of my own home for any decent spread of time: Do I eat crappy food now and satisfy that hunger? Or do I stay hungry for a little longer and eat a healthy meal back at home?

As I pondered this dilemma I couldn't help but notice how much it relates to code quality. But more about food first.

I can only speak for myself, but I do not consider a McDonald's restaurant capable of providing me with a healthy meal. As an aspiring raw fooder, or even as a person who cares what I eat, McDonald's food is far from what I would consider a healthy meal. But, like a lot of you I'm sure, I grew up eating McDonald's without questioning its health benefits. I was hungry and McDonald's was food.

Now that I understand the short and long-term effects of McDonald's on my body I avoid it all costs. The same goes for pre-processed foods in general. This has been a journey for me. Deciding to change your eating habits is more than a one-day process and healthy eating is a continuum.

This'll all relate to programming very soon :)

Healthy Eating is a Continuum?

Eating at McDonald's is not a healthy meal. However eating a Big Mac with a side salad is marginally healthier than eating a Big Mac with fries. Eating a tuna wrap from Starbucks is marginally healthier than any meal containing a Big Mac. Eating a bowl of soup from your local boutique coffee shop is marginally healthier than a tuna wrap from Starbucks. Eating a homemade meal with fresh ingredients is healthier than any of these meals.

There are two takeaways from our look at food:

  1. Everything is relative. You can almost always do better and almost always do worse. Eating a Big Mac does not equal death, but refraining from food for an entire day in anticipation of a homemade meal is obviously not healthy either.

  2. Every meal is anew. It's very easy to get into traps like "Well, I had a Big Mac yesterday so I might as well have another one today". That kind of thinking is not logical or helpful. Every decision to eat is a new decision. Even if you had a Big Mac for breakfast today, having a home-made meal for lunch is a step up on that continuum.

Code as Food

Much like food, code quality is a continuum.

At a very basic level we can say that a library that ships with no tests and no documentation is of lower quality than the same library with tests and documentation.

But between the obvious is a lot of murky water. Everyone has their own ideas about what is 'healthy' code. Some people are very aware of their programming habits and work on improving them. Some people are doing the same crap they've been doing for years without a thought to whether or not it's 'healthy'.

Making Healthy Choices

Treat code like food.

Just like you have to eat, you have to ship code. But how you do that has both short- and long-term effects.

If you take the McDonald's approach and ship shit then you satisfy that need in the short-term. But you'll feel the effects in the long-term. Your code will be harder to maintain and need more attention later. It won't have a long and healthy life.

If you take the home-made meal approach then you leave that need unsatisfied for a little while. The short-term effect is that you stay hungry, but it's for a good reason: the long-term effects will be positive. Your code will be easier to maintain, bugs will be easier to fix, and it will be easier to introduce change. Your code will have a long and healthy life.


Writing healthy code requires the same thing that healthy eating does: recognition and commitment. To go from eating poorly to eating well requires a recognition that there's something that needs improvement. To act on that recognition requires commitment to your decision.

To improve your programming habits requires the same: recognition that something needs to be improved and the commitment to do so.

As always, your choices must be pragmatic. You have to eat something, and your code has to ship sometime. In lieu of finding a healthy meal McDonald's will have to do. I don't know the constraints of your software project, and sometimes you'll have to ship shit. Just remember that healthy programming is a continuum. Get a side salad with that Big Mac instead of fries.

There is no 'healthiest' meal. You can spend all day preparing the healthiest meal you can imagine but it does no good unless it's in your stomach. Code quality is important, but it's nothing unless you ship it.

The surest path to healthier code is incremental improvements. Program a little bit healthier every day rather than discarding the old habits in one go and expecting them to be replaced by new, healthy ones.

I'm Jesse Storimer. Follow me on Twitter.

Get my eBook, Working With Unix Processes, and become a Unix guru without any C programming.

Like what you read?

Join 2,000+ Ruby programmers improving their skills with exclusive content about digging deeper with sockets, processes, threads, and more - delivered to your inbox weekly.

I'll never send spam and you can unsubscribe any time.

comments powered by Disqus