The Joy of Programming

I program for most of the day at work. Not everyone in the office knows how to program, and to them it could just be magic. Granted, for the most part, they do advertising, marketing and sales, and I don't think I would succeed in those domains at all. Nevertheless, this is about the joy of programming rather than the joy of marketing.

What I've been asked before is how I go about solving a problem. In the moment I couldn't really give a good answer - at least an answer that wouldn't make me sound like a snob. "I just know and then I do" would make me sound like an ass.

Let's step back a little. What even is programming? Well, superficially, it's a means by which we can create a program - but that just kicks the definition can down the road. Programming is a way in which we can create a set of instructions for specific hardware (computers) that when executed perform desirable effects. That code could be simple as adding up numbers all the way to the code that runs the servers that allows this e-ink to be transmitted from my computer to yours. Let's start by asking whether programming is an art, a science or a philosophy. I don’t mean to derail the piece too much but in typical polymath fashion we need to ask what is art, philosophy and science? Starting with art, as always, we turn to Ayn Rand’s The Romantic Manifesto. Rand defines art as "a selective re-creation of reality according to an artist’s metaphysical value-judgments". Science is really the study of natural phenomena – which in turn can be used to engineer solutions to problems. Philosophy is the study of the fundamental nature of knowledge, reality and existence and is the means by which we can determine values.

In the art camp we can certainly find some arguments. Every programmer values beautiful code and beautiful solutions to problems. What is beautiful though? Some programmers consider an object-orientated style to be beautiful – I think this is the most grotesque distortion of code possible. In either case, we, the programmer, are recreating our vision according to our metaphysical value judgements. A lot of the joy and value in programming is in the aesthetics of the code on the screen, and the aesthetics of an elegant solution. In another way, sometimes mapping out coding projects is more of art than a science since we can't always approach every problem in a totally scientific manner - they are too big, too complex, for one mind to hold so we go about them in a more holistic manner.

There are strong arguments for programming being a science too. It's easy to abstract away from what's really going on and think about "objects" - but in reality everything is just 1s and 0s in hardware (even this is an abstraction from what's really going on!). At it's core programming is a way for us to systematically manipulate electrons in silicone to compute solutions to problems. Sounds pretty scientific. More than this, programming certainly relies on observing natural phenomena and then engineering solutions based on this scientific knowledge.

Finally in the philosophy arguments programming is deeply thought provoking. My team can argue for hours over the best way to structure a program, what the program should do, how the user should engage. A lot of early programming texts should be seen as philosophy texts more than anything. Referring earlier to those metaphysical value-judgments: how do we determine what they are? Through philosophy. Indeed, for Rand art was downstream from philosophy. Already in this article I have been throwing around terms like "problem" and "solution" – how do we identify and determine what is a problem? How are we then sure what we create is an appropriate solution? Through philosophy.

My study of logic has dramatically improved my programming skills. I saved this for after the previous discussion though: as there isn't exactly a clear consensus on whether logic is a science or a philosophy – and that discussion is well beyond the scope of this article. Just know that logic is more than useful for programming!

So, how do I go about solving a programming problem? Do I treat it as an art, a science or a philosophy? Well, all three at once I suppose. The thing the question "how do you solve problems" misses is that I am not simply a programmer, a philosopher, a scientist, a mathematician (this applies not only to programming!) plucked from the void and presented with a problem. I have, in my life, done thousands and thousands of mathematical, programming and logic problems. I have developed an intuition for solving problems of this style. I can remember past problems that I've solved - we often keep a nice repository of them on GitHub. What this is to say is that when you see some genius programmer with a finished problem you might mistake this for "talent". What you probably missed was the hundreds of hours of practice that they have done in their life and the many hours of figuring out how to get the program to fit together and work.

So where does the joy of programming come from? Is it programming as a science, a philosophy or an art joyful? All three, I would say. Grinding away at a hard problem until you arrive at a full working solution is a scientific aspect of programming - and it certainly is satisfying when the code finally complies and behaves as you expect it to. When you refactor code to be more maintainable and aesthetic there is a deep satisfaction and joy. Many times I've felt relieved and liberated when a "stinky" piece of code has been cleaned up - it's a similar feeling to decluttering your house. The philosophy is joyful, too - thinking hard about good ways of structuring whole programs in a more abstract sense is also joyful.

Programming is really about generalisations. Sure, in many cases I could make something that solves that specific problem much faster than I could write a program to solve all problems of that class - but if I spent my time writing specific solution after specific solution it would, in the long term, take far more time. Instead, we want to think about concrete problems and then generalise to solve all similar problems. This is deeply a philosophy - and it is itself guided by a philosophy. I value my time. I need philosophy outside of programming to come to the conclusion that I value my time.

I've worked in a "stinky" repository many times – by "stinky" I mean one that is messy. It's hard to find where things actually happen, is disorganised, cluttered and overly complex. Eventually the stink just becomes too much and I rewrite the whole thing from the bottom up in order to refactor it. I just needed to in order to carry on working - the stress caused by messy code is intense. Really by the time I'm done with the frantic rewriting the stress relieved is great – and more than that, proceeding further becomes quicker and easier,.

I think the overall goal of this piece is to promote two ideas. One, philosophy isn't dead. The idea that we no longer have a need for philosophy because we instead have science is laughable indeed. The second idea is that we need a truly polymath approach to most problems in order to solve them. If you come into programming as a philosopher, a scientist and an artist solving problems becomes much easier and more joyful.