What is Programming?
In the past 50 years, computers have gone from the room-sized stuff of the space program and science fiction to devices so small and ubiquitous that they're boring. Your car and microwave, for example, have computing power undreamed of half a century ago. The computer or tablet or phone you're reading this on is so much more powerful than the computers that sent astronauts into space that no one in the Apollo program would have dared to believe they would ever exist.
Despite science fiction predictions (and warnings) that computers would automate away all of the work of humans, humans have more power than ever over computers. Humans are vital to the work of computers—because only humans can program computers.
What exactly is programming?
A Program is a Set of Instructions
A computer is a simple device that knows how to remember things and how to look up those memories. At its core, that's all it does. It starts out with a blank slate of memory and relies on a human to tell it what to do with that memory. This was true of the first computers and it's true of modern devices; the history of computing shows an increase in the complexity of the mathematical transformations possible.
Put more simply, your phone is countless times more powerful than the computers that sent astronauts to the moon and back. In a couple of human generations, we've seen dozens of generations of computers.
A computer program is a set of instructions for managing that memory. Whatever you want to do with a computer, you're manipulating a set of electrical symbols the computer understands in a particular way. This is obvious if you're running a calculator program (take 10% off the price of this $43 sweater) and less obvious (but no less true) if you're writing a document. Think about it this way; every word you type has to be in memory somewhere, right? The same goes for a sentence you emphasize as and a word you write as bold. Even the changes you make to move one paragraph here or delete a sentence are themselves stored in memory so that you can hit undo to revert a change you didn't intend.
A Program is a Complicated System Built from Simple Parts
Ever play the game Monopoly? The rules sound pretty simple. You roll the dice, move your token that many spaces around the board, and follow the directions where you land. They're easy to describe in a page or two. (Is programming easy? That depends what you're doing.)
The game is never quite the same, though. Maybe you add some rules, like putting all of the fines collected on the Free Parking space, and the first person who lands there gets to collect the money. Maybe you let players take loans from the bank without mortgaging properties.
Maybe you've run into a situation where two players disagree over the interpretation of a specific rule, and you have to read the rule out loud and discuss what a single word in that rule really means, and why the game designers chose that word over another word. Sometimes you agree on one interpretation with one group of players and another interpretation with another group of players.
The rules—as simple as they might seem—produce a framework in which countless players have played innumerable games, each one a little different. One player's strategy is not another's, and one roll of the dice can change the entire game.
Programming is like that. Programming means implementing the rules in such a way that complicated systems are possible. Programming means discovering and building systems out of these kinds of rules. Good programming tries to minimize the number and complexity and potential ambiguity of the rules to maximize the flexibility, ease, and correctness of a system. In a very real sense, programming means coming up with the rules for a process and combining them in a coherent way. Programming rules can be simple or complex, but they're usually part of a larger system in which the interaction of multiple rules leads to consequences intended and not!
Programming isn't a series of equations. Programming's also a little messy where it interacts with the real world. It has to deal with the fundamental ambiguities of human language and communication. (If you think quantum mechanics is weird, try linguistics sometime!)
A Program is a Mathematical Proof
For every right triangle, the old Greek thinker Pythagoras discovered, the sum of the square of the lengths of the sides which make the right angle is equal to the square of the length of the remaining side. (You can prove this trivially yourself.) Every triangle which matches this property is a right triangle. Every triangle for which this is not true is not a right triangle. Mathematicians try to discover and express relationships and identities like this every day.
Programming is like that.
If programming is like coming up with the rules to a board game, it's also like discovering invariant properties to a complicated system. "It's impossible to withdraw more money from the ATM than you have in your savings account," one program might say. "It's impossible for the airplane to take off while the cockpit door is open," another might explain.
Computer programs in the real world often have to be more complicated than the rules of a board game. They have to deal with objects in the real world: money, cars, books, employees, paychecks, automatic sprinkler systems. Even though a computer program is ephemeral and untouchable, it has to deal with reality. "If the sprinkler system runs for more than 20 minutes, it'll overflow the pipes and cause damage to the floorboards, so cut it off at a maximum of 19 minutes." These are simple machines, but their interactions are anything but simple. They're logical, yes. On their own they're small but functional. Together, they make complex systems.
These rules may seem arbitrary, even when they have their roots in the real world, but they're anything but arbitrary in the world of the computer program. They're the rules by which the world of the program operates. Writing a program often means designing an ideal version of the real world and setting up these rules that cannot be violated.
If you know that a right triangle always has the property that follows the Pythagorean theorem, you can build up more complicated systems. You know something that will never change, and you can make more and more assertions based on the combinations of these simple rules. Just like Monopoly can't only be "Roll the dice" but has to include buying and selling properties and paying rent and passing Go to collect $200, any computer program which does anything useful in the real world must make assertions about the world it inhabits and define a set of rules built on rules built on rules from there.
Good programmers can see these patterns. Great programmers exploit them.
A Program is a Solution to a Problem
A computer program must touch the real world somehow. Even if it's as simple as giving you a calculator so you don't have to do long division in your head, it has to follow the rules of the real world, where 27 divided by 3 is 9. A calculator that couldn't get that right would be awkward and difficult to use.
Similarly, a program that has inconsistent rules or rules which don't match your expectations will be frustrating (at best) to use or impossible or expensive or dangerous (at worst). A space probe that doesn't understand gravity might smack into a planet. A spreadsheet that silently forgets about compound interest may cost you lots of money. A brake sensor that can't detect temperatures above a hundred degrees might not warn you of a failure in time to react quickly enough. A music program that plays the wrong notes isn't even worthwhile for jazz. A drawing program that can't draw straight lines isn't worth the binary bits it's made of.
A computer program always touches the real world somehow, else why would it be written? Even a program written for the sake of writing it has the real effect of generating pleasure by being a piece of art or the comforting diversion of a hobby. Real life always finds a way to intrude into our carefully crafted models, and our software is all the better for it.
A program need not concern itself with the laws of physics which bind the real world; a game might have a zero gravity mode where players bounce around in space like balloons. Yet a program to calculate the amount of cement necessary to use in bridge pilings to support rush hour traffic across a bridge needs to follow the real world to a great degree.
Programming is a Creative Act of Design and Discovery
What is programming?
Programming is discovering a set of rules with real world effects.
Programming is designing idealized representations of these rules and the real world objects affected by these rules.
Programming is understanding the interactions of these rules and their objects.
Programming is optimizing the interactions of these rules for the constraints of safety, budget, correctness, and other resources.
Programming is a complicated activity that requires discipline and patience and practice and study—like any creative act. It is part logic and proof (like math) and part design (like producing a board game that is easy to understand but fun to play). It can be difficult and enjoyable at the same time.
Programming is not easy (what worthwhile human endeavor is?), but it is essential to multiplying the power of human creativity and effort to meet the needs and realize the goals of our modern world.Tweet