Beth Academy
Lesson 02

How Computers Interpret Instructions

A.K.A. "Why are genies like that?"

Grocery Store Parable

There's a really old software development joke that goes something like this:

A woman asks her programmer husband to run to the grocery store.

"Get a carton of eggs." she says, "If they have fresh donuts, get a dozen."

To her bewilderment, her husband comes home with twelve cartons of eggs.

"Why did you buy so many eggs?" she asks.

He smiles and replies, "Because they had fresh donuts."


Her mistake was not specifying that he should specifically buy a dozen donuts. She told him that the thing he should buy is a single carton of eggs. She set up a "rule" that increases the quantity to twelve, but she didn't tell him to apply it to a different food item.

E.g. "Get a carton of eggs. If they have fresh donuts, get a dozen donuts."

Even that wouldn't be enough, because then he would have came home with just donuts and no eggs, because "donuts" became the thing he needed to get, and she didn't specify he should get both.

(Actually she never even told him to specifically purchase anything, so he probably would've been followed home by the police.)

Her request should have been something more like:

But even that expanded description would still have some bugs.

He wasn't told to put the donuts into a box or a bag, so he'd be placing them directly into the cart and car.

He wasn't told to take his shopping cart with him to check for fresh donuts, so he'd have to carry all twelve donuts back to where he left the cart, near the eggs.

He wasn't told to close the doors of the car after putting the items inside, so they would stay open after he put them in the car.

But hey, at least he'd have come home with all of the correct items.


This is the type of rigid logic that computers follow, and the vast overwhelming majority of bugs that you experience will be a similar class of problem to what the wife of this man-child had to go through.

Computers have zero common sense whatsoever. They do not know or care what your intentions are. They will do exactly what you tell them to do, exactly how you tell them to do it, with zero ability to course correct through intuition.

The very first skill you will need to practice is getting used to thinking like a computer; breaking down your instructions into detailed individual steps, with no room for "common sense" to come into play.

Along with that, you'll also need to practice being able to examine your written instructions after the fact, to figure out where you weren't specific enough about what you wanted.

The computer will almost never do exactly what you pictured in your head on its very first try. Having code work correctly on the first attempt is extremely rare.

When you start a new project and type the first letter of the first line of code, your program will be "broken", until you've fixed all of the logic issues and everything is complete.


Practice Makes Perfect

We'll start diving into some actual code in Lesson 03, but I think it'd be good for you to practice giving rigid logical instructions before that, so you can start getting used to how it feels to think that way.

Lightbot

Lightbot is a puzzle game, where you drag instructions for the robot to follow, and your goal is to get it to "Light" up all of the blue squares.

There's a paid ($2.99) equivalent of it on iOS and Android, but the version I linked is free, and it's a decent way to practice this type of thinking until you start writing code.

You're not required to beat every level (it's not that fun despite its usefulness as a practice tool), but I recommend doing as many levels as you can until your brain says no.

And if anyone is interested in doing the Lightbot practice but finds the game's lack of tutorial to be an obstacle, let me know and I'll record a quick tutorial video of the first level.

(The Steam game Human Resource Machine is a much more polished game in the same genre, but costs money.)

Optional Homework Assignment

The fastest way to improve at programming in general, is to take some code you've written (or pasted from examples), and just play around with it to do different things.

So I'd like to propose a challenge to anyone who might feel motivated (it's okay if none of you do this):

After you've gotten through a few levels of Lightbot, instead of trying to accomplish the goal, see if you can make the robot "dance" instead, and post a clip of the dance you made in the #discussion channel for Computer Science.

As I've said before, no one is required to participate in the discussions, so it's okay if you make your robot dance, but choose not to share it. (The practice itself is what matters.)

Sometime before Lesson 03 is released, I'll record a video of myself doing a few Lightbot levels and explaining my thought process (especially if anyone finds a particular level troublesome), and share my own robot dance clip.