Why I Code Golf

Let’s start off by defining what code golfing is. It is the challenge of “writing a piece of code as concisely as possible.” More technically, it is to minimize the number of characters or bytes need to represent that program. In practice, this means first writing some code, and then gradually reducing it bit by bit until we can’t anymore.

First of all, there’s the challenge. Software engineering, in one sense, has become the art of making glue. Let’s say I need to build a chat app. The paradigm nowadays (and rightly so) is to pick a server, and a pub/sub service, and a web framework, and a templating engine, etc. and write glue that connects them all. This is fine and there are varying qualities of how these are put together. Now compare code golfing; there is only one shortest possible way to express a program, and it becomes a goal to strive for. Think of how a body-builder has a target fat percentage, or how a chess player has ELO.

Next there is the competition. Sites like Anarchy Golf and /r/tinycode allow us to pit ourselves against other code golfers to see how we stack up against each other. As in any competition, there is a winner, but the losers also get to learn new techniques to apply in the future.

Finally there is the art. For a lot of golfed code, I wouldn’t call beautiful in the usual sense. But they are elegant. The process of refining a program down to its very basics is akin to Picasso’s abstraction of a bull. Every piece of waste is removed and only the essence is left.

Written on Feb 13, 2014 about Code and Golf.