Comments set off with some special marker (curly {braces} in the English computer, a pair of forward slants "//" in Java), whose sole purpose it to be messages frrom the programmer to themselves or other programmers looking at the code. The computer completely ignores them, except to show them when the program code is printed.Numbers like 123 or 0 or 3.141592, and they stand for the numbers you would expect.
"String" constants enclosed in quotation marks like "Hello" and "123" and "+" which stand for the sequence of letters and other characters on your computer keyboard, exactly those characters between the quotation marks and nothing else ever. A pair of quotation marks with nothing between them -- "" -- is simply the empty string, that is it is a string with no letters or characters at all. It is useful as a starting place for building larger strings by adding on letters, and also for comparing to input to see if nothing came (the user pressed Enter without typing anything else first). See additional comments below.
"Reserved" (magic) words that mean only one thing in that language. There are usually dozens or (raarely) hundreds of these, and you must memorize them to use them. Fortunately you only need to know a small number of them to get started. In the English computer there a few dozen (listed here in the Reference Manual). Examples: Variable and times and bread.
All other names without enclosing quotation marks are names the programmer -- that would be you -- invented to be names of places in memory where data (variables) or code (subroutines) is stored. The programmer decides what name to give it, and the programmer decides what to put there, but the names usually must start with a letter and not have punctuation symbols included.
Some Java programming environments display these five different
kinds of words in different colors to help you see what the computer will
do with them. You will see each of these five types in the following example
program, comments in gray, numbers in black,
variable
names in blue, string constants in green
and reserved words in red, but the English
IDE does not colorize your words. Java IDEs use their predefined colors,
but often you can choose your own preferences.
Here is the program.
1 Variable start= "Hello" {starting word}
2 Variable finish= "" {initial value of result}
3 Variable index= 0
4 Variable lett
5 Repeat
6 Character lett=start,index {get one letter}
7 Add 1 to index
8 If lett< " " then exit {less than any letter}
9 Let finish=lett#finish
10 Next
11 Print "Reverse of " start " is " finish
12 Done
You should convince yourself that you understand it by the time
you finish this page. This is important, because programming is all about
understanding what every single line -- and every word on each line --
means and why it is there. Otherwise you program will not run.
Now if you copy this whole program and paste it into the English
IDE and run it, it will run very fast and print out the result. What
do you think it will print? Try to guess the result before you try it,
then see if you guessed correctly.
When you ClickToRun the IDE will stop with the first line in green (meaning it has not yet run that line), and there is a new "English State" section below your program panel which tells you that it is paused on line 1 and lists the four variables below that. Nothing has run yet, so all the variables are empty.
Now click the blue Step button on the top right. You see the the line has advanced to line 2, and variable start now has "Hello" in it. Why is that?
Step again. Did you see anything change (besides the line number)? I didn't either. because finish was already empty.
Step again. What changed? Each time the computer executes one line of code, and the only thing that changes is the line number and maybe one variable. Do this slowly, one Step at a time, so that you understand each line.
Why is finish built with the letters backwards? What would happen if you changed line 9 to be
9 Letfinish=finish#lettWhat do you think that would do? Try to understand why it is different. This is important, you will have trouble understanding how Seaman needs to work if you cannot follow this simple exercise. If you need help, click the Ask button, or ask another student.
What about line 6? Do you know what the different parts mean? The word Character tells the English computer that you want to get a single character out of the word in start, at character position index (skip over index letters at the front) and put whatever letter it finds there into variable lett. Did you see that happen? Run it again and pause there to see what the variables have, then Step once over that line and see what changed. Do you know why?
Line 7 is easier tounderstand, but it's really the same thing. The command Add tells the computer to add the value 1 to whatever is in variable index. Did you see that happen?
We call this tool a debugger because it helps us see why the computer didn't do what we thought it should do, we can more easily see the "bugs" (errors) in our programs. Later, when you get into Java, it has its own debugger. I should have had this debugger ready for you at the start of the term, but I ran out of time. It still has its own bugs.
If you click on the green Fast button, then ClickToRun goes full speed, as before. You can start a program using the blue Step button and it overrides the Fast mode. You still need to click the Red STOP button (if it's showing) to edit your code. There is additional information in the popup page from the "English State Info" button on the Quick Reference Line.
If you type your Zoom login name into the Zoom Name field, it should
save your program next time you run it. If the program panel is empty and
your name is there, clicking OK should get
your program back. Maybe. It's still beta. Save your code in your own computer
also, just in case.
But what I want to focus on is the name of the command, which starts
with the prefix "sub-" that usually means something like "less than" the
way "subtract" means to "extract a result that is less than the
original," or more often the way "subordinate" means "lower in rank," stuff
like that. Computer people like this prefix, so you will see it a lot.
The rest of this command name is "string" which is a technical word
intended to remind you of a "string of beads" like in this picture. In
ordinary English, a string is something thicker than a thread and thinner
than a rope, but used kind of the same, to tie things together, like these
beads around your neck. In a computer "string" the beads are almost
always individual characters, letters and digits and punctuation and spaces
and line ends, anything you can type on your keyboard. The reason we want
you to think of it as like beads on a string is that computer memory is
always only numbers, one number in each numbered place. Mostly we hide
the numbers that represent the places in memory behind names you choose
in your program, but for text stored on a computer, every letter, every
punctuation or space or digit is given a number that is unique for that
character. You can see the usual keyboard letters and punctuations in the
ASCII (pronounced
"ASK-key") chart in the "ASCII
Codes" section of the "Things You Need to Know
in Java" reference page.
So when you write a program that has a variable containing a whole word like "Hello" in it, somewhere in memory there are five memory cells in a row, containing the numbers 72 ('H'), 101 ('e'), 108 ('l') twice, then 111 ('o'), or else different numbers for other words. Some part of the system software (the program you didn't write) works hard to keep these five numbers together and in order and connected to whatever name you gave your variable.
Real people like you and me, we think in words and sentences, not numbers, so the computer technologists put a lot of effort into making the computers pretend to think in words and sentences like us people. But it's all fake. Somewhere down in the guts of the computer are a bunch of programs that somebody wrote to do the work of keeping the numbers representing letters together as words and sentences. That somebody will sometimes be you, at least when you need to pick letters out of the words and poke them back into other words. When you step through the program above, you can watch the program pick a single letter out, then pack it into another word in reverse order. You need to understand what is happening, One. Step. At. A. Time, because almost all the programs we do in this workshop communicate with people, and people think in words, and your program needs to be able to do that.
If you have trouble understanding strings after stepping through this program in the debugger, it is because I didn't explain it very well. I need to know, so PLEASE, click the Ask button in Zoom and a mentor will come help you. They will also tell me what's missing.
DO NOT SKIP THIS STEP, IT IS IMPORTANT. Ask for help if you have trouble understanding it. You and I will both be better off if you ask.
[2021 November 11]