An Introduction to Computer Programming
Copyright 2023 Brian Davis - CC-BY-NC-SA
This work is equal parts introductory textbook and polyglot spell tome. I will attempt to describe the fundamentals of computer programming as art, craft, and science for the neophyte student and alongside these concepts, document the incantations I have learned in a variety of dialects.
The only prerequisites are a sense of humor and an eclectic vocabulary (or at least a willingness to look up some of my stranger word choices).
Ex nihilo mundos - from nothing, worlds.
It is quite common for practitioners of computer programming to develop something of an ego. Several factors contribute to this phenomenon. First, programming essentially boils down to an endless series of logical puzzles to be solved and while that might sound mundane, solving these puzzles creates, as if from thin air, entire virtual worlds. The most banal business software, through the eyes of the programmer, is a vast machine, at once beautiful in it's complexity and elegant in it's simplicity. We're not called nerds for nothing but also, don't knock it if you haven't tried it. The act of creating these vast machines inside mechanical minds can be powerfully intoxicating.
That's not to say it can't also be boring, repetitive, and frustrating, maddening even. But I don't see many programmers who have pursued this profession, yet never tasted the allure of the power of creation.
Alongside this puzzle solving power, programming also involves much peddling in secret knowledge. Many a problem will be solved, barrier penetrated, or crisis averted by the hoarder of esoteric facts. The one who has traveled far and filled her mind with oddly shaped runes will find much praise when the online shopping portal (and with it the monthly revenue) is saved from doom by just the right spell garnered from some dark IRC channel of ancient times. It can indeed be difficult to not feel superior to mere mortals.
The problem with ego is that it is a barrier to learning and of all fields of engineering, of inquiries of science and explorations of art, the programmer's world is most vast, and ever expanding. The practitioner must then be a perennial student, or else despair of any mastery.
To these ends, to sow humility in myself and other students of these arts, and to lay a properly solid foundation for this exploration, I introduce my first law of computers.
The First Law
Computers only ever do exactly what they are told to do.
Despite how it feels sometimes, our daemons have no will. We do not wrest power from them when we bind them to a socket, instead we alone imbue power into the totems of our creation. Thus their success is our glory and their failure is our shame. One can blame the tool all he wants, yet it is futile. The tool has no motive force sans craftsman.
The smith must learn her metal, what occurs inside the ingot when she heats it to glowing red, to warm yellow, or to blazing white? When quenched in oil what properties alter? Each hammer stroke effects what change? This is her craft, to know in her mind every step of the process and what the result will be before even the coals are hot.
So to is the craft of the programmer. The computer is both ingot and anvil, material and tool. You must know before your fingers touch the keyboard what it will do when you command it because it will do nothing but exactly what you command it.
The computer is a precision instrument. There is no room for ambiguity. The painter may add emotion to his work by subtle deviations of the brush, by unexpected splashes of color. The pianist does not merely mechanically reproduce the sheet music. He will vary his timing and force to convey some humanity to his work. But the programmer's tools are razor blades powered by hydraulics rotating at 10,000 rpm. Each nano(meter|second) must be specified, every ambiguity rendered to perfect detail.
The computer programmer must first build a computer in her mind. Her code must run there first. When in the real world her computer produces an unexpected result, the one in her mind is her first tool for understanding what went wrong.
I will say it again for emphasis: If the program went wrong, it can only ever be your fault. This constant internal self-flagellation is the path to humility but more importantly, it is the only path to understanding and finally mastery. All else is simply playing dice with bits.
That might sound harsh but it's also empowering. If you think of a computer as an unfathomable question/answer box then when the program doesn't do what you expected you'll have no idea where to start to find the problem. But if instead you think of the computer as a hyperliteral idiot then you immediately know to ask yourself two questions:
- What did I mean to tell it to do?
- What did I actually tell it to do?
Because it can't do anything except what you tell it to do. Find the difference between the instructions you meant to give and the instructions that you actually gave and you have found the problem. There is no other possibility.
There will be a lot of code with errors (intentionally and not) in this work. I do not not want you, dear reader, to stare dumbfounded and slack jawed at the error code on the screen like so many before you, like even your humble author does all too often. I want you to return to the machine in your mind. Step it through each instruction, simulate the result, and compare it to your desire. In our virtual worlds we are near enough to omnipotent. Our greatest limitation is the ability to accurately describe the difference between reality at present and our imagined future.