Late-Breaking News (PBJ)

(This Is Not In the Video)

Sequence

A very important part of programming is getting things in the right order. It's one of Six Essential Ideas that we repeat over and over. Maybe I didn't emphasize it enough in the first video.

In the video, I constructed a small program for making a PBJ. It looked something like this:

"make pbj"
  get stuff
  put it together
  done
The first line has quotes around the whole line.

The next two lines describe something this program does, in the right order, that is, you must get the stuff before you put the sandwich together.

The last line tells the computer that this is the end of the program. If you leave it out, the computer will "Assume" that it belongs there. Later on you will need to put it in, so the computer won't be assuming things. In "real" programming languages, the computer doesn't assume anything, if you leave something out, it won't run correctly, usually not at all.

But today we are working on getting the sequence (the order things happen) correct. Things need to be in this order.

Then I added another program-like piece of code in front of this. I could have put it after, but it won't work if I put it in the middle. Sequence matters. Now we have two -- we call them "subroutines" which is another of those Six Ideas that you will learn, but I didn't use that name in the video -- pieces of the program that have the same shape:

"get stuff"
  get ingredients
  get tools
  done

"make pbj"
  get stuff
  put it together
  done

Notice that the sequence inside each of these chunks is the same, first a name in quotes, then some lines that tell the computer what to do, then the word "done" on a line by itself. There are no blank lines inside this structure. You may also notice that the name on the first subroutine is one of the lines inside the second subroutine. When the computer gets around to doing that line, what it does is "do" the whole subroutine with that name, in the specified order, then goes back to the "make pbj" subroutine to do the next line (put it together), always in the specified order.

Somewhere, somebody must tell the computer to do the "make pbj" subroutine first. If you don't do it in the code (as shown above), then the computer will "Assume" that is what you wanted. But it's better to say so. So somewhere, either at the front or at the end, just not inside a block of code that begins with a line in quotes, we added one more line (with no quotes) shown here in blue:

"get stuff"
  get ingredients
  get tools
  done

"make pbj"
  get stuff
  put it together
  done

do make pbj

The assignment, what you need to complete before you advance to the next video, is to add another subroutine like the one I added in the video. I added another one (in the video) so you can see that it has the same shape as the "get stuff" subroutine, but I gave it a different name, a name matching one of the other lines of what the computer is being told to do. No two subroutines ever have the same name. If you have two lines in a subroutine (or perhaps in two different subroutines) with the same descripion of what to do, and you have a subroutine with that name in quotes, then both lines "call" on that one subroutine to do that task. You will see how that works later, when we get to the Calculator. For now, every line is different.

I need to make this clear. You are going to add one new subroutine to the program shown in the video (it's also in the transcript, and it's easier to scroll down a page of text than waiting through a video to find it), and you need to insert it somewhere that there is already a blank line, at the front, or at the end, or else between existing subroutines, but never inside an existing subroutine. The Kitchen Computer has some other sequence requirements (my fault, not yours), so it's best if you add your new subroutine at the front.

Start with the three subroutines at the end of the video (or in the transcript), don't take anything away, just add another subroutine at the front, with the name "get tools". Inside the new subroutine you will tell the computer how to do that.

Later on, we will be adding single lines of code inside subroutines, but today we -- that would be you -- just add a whole subroutine.

Can you do that?

If you are confused, if you tried to do it and the computer didn't do what you wanted, and you don't see why, summon a Mentor. There's no shame in getting help, programming is quite tricky, and before you know where all the gotchas are, you may need help. After you have been programming twenty years, you still will need help sometimes. And that's OK. I've been programming (seems like) since there were dinosaurs, and I still ask for help, several times a month. Other programmers will know that "you have arrived" (you are a good programmer), when you know to ask for help when you need it. Sometimes you can get help on the internet, and we'll show you later how to do that. For now, that's what we're here for.

Can you do that?

Revised: 2022 October 4