Basic Aspects of ProgrammingI've spent time around computers and/or programming, and sometimes I hear people say things to the effect that what I do is "complicated" or "over [their] head". What that seems to imply to me is, "I could never do that". In this article, I intend to show that not only
could you do that, you may already be thinking or doing things that overlap with the programming field.
Three fundamental aspects of programming could be called 1) performative utterances
[1][2], 2) variables, and 3) logic. At least one of these terms may not be exactly what you'll find in a programming manual, but they'll work for here, especially after I get done clarifying them!
1) Performative utterances
Most of our language reflects reality. When you say "The sky is blue", you're stating a thought about the sky. Your words don't affect the sky, or its color, or anything in particular other than the minds of anyone who might be listening to you speak. But a performative utterance
changes reality. One of the most famous series of these statements is recorded in Genesis 1, beginning with, "Let there be light." When a minister pronounces someone 'man and wife', he is causing, by speaking the words, a change in reality. When a congress passes legislation or an executive issues an order, they too are creating a change, by the act of declaring it to be so, as far as their authority goes. This is what a lot of programming is about.
What sort of things do you declare? Well:
2) Variables
In one sense, a variable is a little like a box. You can fit any 'value', such as an idea, word, phrase, or number, into it, and it is defined by its contents. When you refer to the variable, you mean the thing it has stored.
A variable is also a little like a name. When you use someone's name, you're referring to that person. They may have
more than one name, which are all equally valid in referring to them. Sometimes, you have to be very specific when you're referring to someone, because there are other people with the same or a similar, name, and you don't want there to be any confusion; this can come up in programming as well, although it is outside of the scope of this post.
For a practical example of a variable, if you're budgeting for a road trip, you might think about things like the price of a gallon of gasoline, the mileage per gallon your car gets, and the distance you travel. The price of driving in your trip will be the distance divided by your car's mileage per gallon times the price of gas. Distance, miles per gallon and price of a gallon could be expressed D, M and G. So, the mathematical formula is D / M * G.
D, M, and G are all variables. In this case, they each represent a number, but that number is not fixed. You determine which number you want the variable to represent, then follow the steps of the formula and get a certain result.
As alluded to before, a variable isn't limited to a number. If you're making a roster for a sports team, each open position is a variable, a slot which is filled by one player or another. A password is another kind of a variable; when you provide the correct password, whatever it may have been determined to be in advance, you are authorized for something.
If it is wrong, of course, you're not authorized for that thing, and you'll typically face a consequence, whether receiving an error notice on your computer, or being shot at by a sentry when you couldn't convince them you were from the same military.
3) Logic
Logic involves conditions: "If X, then Y", or perhaps "If X, then Y; else Z". You encounter these kinds of structures every day. Law involves a logical structure, and in this respect, has at least some surface similarity to programming. The Bible also has a large number of these statements, whether they are openly stated, or implied. Mark 11:25-26 is a classical example of an if-then structure. Rewritten slightly, the structure is like:
"If you have anything against someone and do not forgive them, then your Father in heaven will not forgive your trespasses."
The famous message of Acts 2:38 is stated as a command, but it has a logical if-then structure: "If you repent and are baptized in the name of Jesus Christ for the remission of sins, then you will receive the gift of the Holy Ghost".
You can probably also think of many examples from your daily life that involve some kind of logical structure.
4) Practice
Now let's put all of these together to write a simple, natural-language 'program'.
(Source material is one of my previous articles.)
Assuming you use an old Windows PC and need either new software or a new computer...
Explaining the variables:
Money (M) (in dollars)
Desire for software compatibility (S); true or false.
iPhone ownership (I); true or false.
Android ownership (A); true or false.
Fear of big tech companies (F), from 0-4, where 0 is no fear and 4 is paranoia.
English-like "programming language"
If A is true and F is greater than 1, let F be equal to 1.
If I is true and F is greater than 3, let F be equal to 3.
If M is greater than $649, and either I is true OR S is false, and F is less than 4, then get a Mac.
Else if M is greater than 199, and F is less than 3, then stick with Windows.
Else if M is greater than 68, and M is less than 200, and F is less than 2, use a Chromebook.
Else use Linux Mint.
PHP
if(!empty($_POST)){ // See if the form is sent
// Define our variables
$m = (intval($_POST['m'] ?? 0)); // gets user-provided money, or sets $m to 0 if nothing was provided
if(isset($_POST['s'])) {$s = true;} else {$s = false;}
if(isset($_POST['a'])) {$a = true;} else {$a = false;}
if(isset($_POST['i'])) {$i = true;} else {$i = false;}
$f = (intval($_POST['f'] ?? 2));
// Execution phase
if($a && $f > 1){$f = 1;} // fix reported fear to match people's actual purchasing record
if($i && $f > 3){$f = 3;}
if($m > 649 && ($i == 1 || $s == 0) && $f < 4){ echo "Get a Macintosh!";} else
if($m > 199 && $f < 3){ echo "Buy a PC.";} else
if($m > 68 && $m < 200 && $f < 2){ echo "Try a Chromebook?";} else
echo "It's Mint for you!";
}
If the PHP version is lengthier, it's because half of that is from the process of actually collecting the variables from the browser and making sure that they will* work
[3]. The actual execution phase is* both more terse, and functionally equivalent to, the English version provided above.
*
There's never any better time to make a mistake than when you're publishing an example of something that should work, so of course, I expect to find something I missed. This section is definitely open to future revision.
If you get the English version but can't follow the PHP version, that's okay. The important thing is to note that the logic is fundamentally the same. Your weak point isn't intellectual capacity, but the lack of understanding of the grammar and sentence structure of a programming language. That can be fixed if you make the time. If you don't, that's fine, but don't say 'it's over my head'. Instead, you should say, 'I put a higher priority on other things in my life than on learning to read this.'
[1] Something about my original wording seemed off to me, and I found out what it was when I looked it up. Thanks to Virmaior for pointing it out in a comment to this answer.
[2] J.L. Austin's work on 'performative utterances', described here in a Wikipedia article, is relevant. My previous reading of this a while back influenced my writing, particularly in the man-and-wife example.
[3] Here's a demo version of the PHP script which should work, although it isn't very pretty.