Two Attitudes for Programming
Imagine you want to write a Python program that converts fahrenheit to celsius, but when you run your code, you see that your calculated result for 32 degrees fahrenheit is 25.6 degrees celsius. This isn’t right.
You likely have one of two attitudes. The first is correct, and the second is incorrect (and very common).
Attitude 1: The computer runs code according to the rules of the programming language you’re using, in this case, Python. You’ve achieved your goal when the program produces correct outputs for all valid inputs.
Attitude 2: When run, your code causes the computer to produce a myriad of unpredictable results. Programs may achieve your goal, but it’s impossible to know why.
If you have adopted Attitude 1, the mistake in the conversion can be explained by a mistake in your code. If you want to fix the error, you need to find that mistake and correct it.
Attitude 2 is what I refer to as “The Code Happens to Me”. If you have adopted Attitude 2, 25.6 is a bizarre result, and we don’t know why it happened. Maybe running the code again will work? Let’s change a plus sign to a minus, or a division to a multiplication and cross our fingers.
Attitude 2 minimizes your agency as you attempt to create software and is caused by bad explanations of what programming is.
Two Bad Explanations of What Programming Is
To explain programming, people try to use metaphors like “learning to program is like learning a foreign language” or “learning to program is like putting together a puzzle”.
Someone learning English, Spanish, or Korean has an idea for a sentence in their mind and wants to translate that idea into something the foreign listener can interpret and understand. There are many suitable translations, and the foreign listener will likely be able to understand a translation with many errors. Once a sentence has been communicated correctly, you’re all set!
This is not how programming works. Code written in a programming language needs to be precise, and a computer is unlikely to accept a program with errors. Even if a program is “understood” in the sense that it runs, that’s not the end of the story. A program works if it produces correct outputs for all valid inputs. Programming isn’t about communicating an idea, it’s about specifying a process for handling inputs and outputs.
The puzzle solving metaphor is possibly more pernicious than the translation metaphor. While solving a puzzle, two pieces belong together in the solution if and only if they fit together. (Let’s call this The Puzzle Theorem) “Getting the puzzles to fit together” is best mapped to the programming task of writing syntactically correct code, that is, code that is “understood” by the computer and runs.
You can become quickly confused when faced with the falsehood of The Puzzle Theorem while trying to code. “Making the pieces fit” is only one piece of the puzzle (pun intended), and more crucially, there is no one correct way to implement a program in code. If you expect programming to be a journey towards a single correct answer by rearranging puzzle pieces, you’re in for quite a long ride. (Google “combinatorial explosion”)
The Real Process of Programming
To write a program, here’s what really needs to happen:
You are given (or identify) a goal and are given (or identify) a specification for a program that will achieve that goal. In our example, this is converting farenheit to celsius.
You translate that specification into code in the programming language of your choice.
The computer runs the program with a set of inputs.
The creator of the specification interprets the output of the program as either meeting or failing to meet the original goal.
Here are important features of this process:
The creator of the specification (possibly you!) exercises a large degree of creativity.
There is a significant challenge in translating the specification, usually written in natural language, into a programming language. (“coding”)
You can exercise a large degree of creativity in the use of the programming language as there are many ways to write a correct program.
The program may behave correctly given certain inputs, but fail given other inputs.
The primary cause of the “Code Happens to Me” attitude is confusion as to where you can exercise creativity and how a program is deemed to be correct. Many beginning programmers produce code and ask “is this right?” without once running it. If you’re translating Chinese to German or building a puzzle, this question is at least sensible, but in the context of programming this question demonstrates a categorical misunderstanding.
In programming, the code is the primary independent variable under your control. Without a means of assessing whether a change to that variable has a positive or negative effect, programming will feel at best mysterious, and at worst a useless exercise in the arbitrary arrangement of abstract symbols.
Spreading the message that “Code Doesn’t Happen to You” is the primary goal of this newsletter. To understand programming, you must develop the right attitude first. Once you truly understand this, a world of creative expression opens up, ready for exploration.

