I’ve often found myself providing others with simple explanations of fundamental programming concepts. While I’m by no means committed to writing an Ultimate Programming Primer, my work on The Ultimate PC Primer got me thinking: what analogies, stories, or props would I use to explain the basics of programming/scripting to total newcomers?
Learning how to write a “virtual recipe” can be difficult, since computer languages, as with real spoken and written languages, require correct grammar. In fact, computers are unforgiving with grammar, and usually they’re not smart enough to guess at what you mean. So, programming is challenging due to the precision required as well as the foreign nature of the structural concepts. And that’s why comparing the intangible to something physical — something from the real world — is often so handy.
Here’s how I explain four of the most common computer scripting/programming concepts to newcomers trying to grasp them, leveraging a few common household items. (Since I haven’t included photos of each of these, be sure to see the video at the bottom of this post to grasp the power of the visuals.)
Variables: They’re the most common way to temporarily hold onto a piece of information for the program to use it later. The real-world analogy: Tuppwerware (or any kind of food plastic storage container.) Assign a name on the lid and stick something inside the container.
Arrays: It’s like a series of containers linked together, sequentially. Think of a daily pill dispenser/scheduler. A single unit with multiple individual compartments, all in a row.
Strings: A series of characters (letters and numbers) all “strung” together, like popcorn on a string. But in this case, letters and numbers on a literal piece of string. (A shoelace works well, and an elastic band works even better as you’ll see in the video).
Length: It’s common for programmers to need to determine how many items are in an array or the number of characters in a sequential piece (string) of text at any given moment. While some languages use “count” for this function (which would be obvious), most use “length.” A helpful analogy: gold chains that are sold by the inch, where each segment of the chain is an inch. The length of the chain is determined by counting the segments, which is exactly what a computer does to return the length of a string or array: count the total.
And here’s the video explanation illustrating the use of these items.