Telling the Computer in a Language

Let's pause and review where you are, and how it fits in the Big Picture of programming.

When you put letters together and form words and sentences on a sheet of paper or a computer screen, there are rules for doing that, and the set of rules is called a language. When you put sounds together in the air, the rules are slightly different, but it's still a language because we assign meaning to those sounds or words, and somebody else -- or in our case, a computer -- can understand that meaning and do what you are telling it (or them) to do. They are using the same rules to understand what you said as you used to say it. That's the beauty of language, and it's only in the last 80 years that we figured out how to make an inanimate object, a chunk of plastic and glass and metal and a few other chemicals, do that. That's what you now, today, know how to do. It's awesome. We programmers control the world!

But Chomp is not the whole world, it's only a first step. Most of the world out there is programmed in a language called "C". Teachers give a grade "C" to students who did not do well enough to earn an "A" or "B" and the language is well named. But it's the real world. Java is another language, sort of like C only better. Once you know Java, it's an easy step to learn C, see for example my essay "C++ for Java Programmers". So I encourage people to learn Java first. The computer will help you -- not as much as the computer helped you to learn Chomp, but lots more than people trying to learn C first.

Programming is a very demanding task, it's very easy to make mistakes, and we need all the help we can get. In Texas they say "Don't take a knife to a gun fight." Programming computers is the gun fight, and C is the knife. Java is more like a handgun. There are AK-47s out there, but some guys think martial arts (hand-to-hand combat, not even a knife) is more macho. Maybe it shows how much iron they pumped, or how many steroids they consumed, but it doesn't win the battle. Choose your fight, then win it. That's why Java is a good programming language to learn (see also my essay "Why Java?"), and that's why I teach it. Be the best you can be! Make the world a better place.

Six Things

There are many computer programming languages, but every one of them does six essential things. The only difference is how you spell the words to do those six things. It's kind of like you can arrive in any city in Europe and find the center of town (where the stores and hotels and restaurants are) with one question: "Where is the train station?" But each country speaks a different language, and you must ask your question in the language of the people. In France you ask "Ou est la gare?" (pronounced more like "Oo aye lah gagh" because the French 'r' is more like a gargle to the rest of us). In Germany it's "Wo ist der bahnhof?" (the 'w' is pronounced like the English 'v', so you say "voh ist dare..."). In Spain it's "Donde esta la estacion de tren?" It's spelled (and pronounced) different in each language, but it has the same effect.

These are the six things that every programming language does, and you have already done all six of them in Chomp:

Sequence -- arranging your steps to run in order

Variable assignment & expressions -- calculating values and saving values for multiple or later use

Conditionals -- choosing to do one thing or another, but not both

Iteration -- repeating some operation(s) multiple times

Subroutines -- giving a name to some operations, so you can call it by name in different contexts

Input & Output -- getting outside data into the computer, and getting the results back out


In Chomp, like in the original Fortran and Basic, you had numbered lines, one command per line. Most programming languages separate their commands (statements) with some kind of punctuation, like a semicolon in C and Java, or parentheses in Lisp. In C and Java the semicolon is called a terminator because it's required even if there's not another statement following.

Variable Assignment & Expressions

Most languages, starting with Fortran (the name is short for "Formula Translation"), use something resembling a mathematical equation for their assignments and expressions, but you must not confuse the algebraic notion of equality with the programming concept of assignment. C and Java make that confusion easy because you can put an assignment anywhere, but you should avoid it. Chomp follows the original Basic in requiring a keyword "let" for assignments. The other languages see the assignment operator '=' to know that's what you are doing.

There are a few languages that use names for some or all arithmetic operations and a tiny minority of academic languages use special characters not on a standard keyboard, but every other language uses the standard '+', '-', '*', '/' originally introduced in Fortran for the four arithmetic operations. Fortran did not have symbols for comparing less or greater on the keypunch keyboards at that time (programmers subtracted and tested for zero, which you can still do in C and Java and Chomp), but Basic was originally mostly programmed from the ASCII (pronounced "ass-key") keyboards of Teletype terminals so they did their comparisons using the same '<', '=', '>' symbols you learned in Chomp. Java follows C in defining the additional 2-character symbols '<=', '>=', '!=" (unequal) and especially '==' (equality, so it's spelled different from the assignment operator '=', which often gets mistakenly used in the same place and the compiler accepts it as valid). There are other "bit" operators which the computer hardware does easy, and which C exposed to programmers, but I'll get into them when we get there in Java.


All the programming languages I know about (except Lisp and its derivatives) use the English word "if" to designate the most common form of conditional, and most of them use the English word "else" for the alternative, the same as you learned in Chomp. In some languages -- Chomp is like C and Java -- the conditional controls exactly one statement in the respective true and false parts (but you can collect multiple statements into a single group statement to be used there); other languages require an explicit terminator like "endif" so that you can have any number of statements in the respective bodies. Many languages, including C and Java but not Chomp, also let you choose a single alternative out of a numbered or otherwise labeled set of many choices, but you can always do the same thing with sequences of if..else. Again, I'll get into that when we get there in Java.


There are all kinds of different spellings for slightly different ways to do iteration in the many programming languages. The most common form originated in Fortran and designates a control variable to step up one unit at a time to a specified termination value; Fortran used the English keyword "DO" to set that up, but everybody else now spells their keyword "for". Another common form uses the English keyword "while" to specify a condition which must be true for the iteration to repeat. For Chomp I borrowed the keyword "repeat" from HyperTalk, which is one of the compilers I wrote. Once you learn the Java vocabulary, it will be easy to translate them (in your mind) into however they are spelled in whatever new language you need to learn.


The name "subroutine" was used in Fortran to designate a named sequence of statements (think: "commands" in Chomp) that you could call from different places in your program, but every programming language (including Chomp, using different user names) now has them, although now they are more often called "function" or "method" (but it's the same thing). The mathematic word "function" implies that they return a value; "method" is the preferred word to use in so-called "Object-Oriented" programming systems -- which I call "OOPS" because the real world is not nearly so object-oriented as their defenders claim, and because they didn't really offer much of an improvement over what they are said to replace. But that's politics or religion (which mostly seems to mean "believing what you know ain't so"); we will stick to the cold hard facts of programming 

Every programming language comes with a pre-defined collection of subroutines to do the complicated things most programmers need to do, called a library. At the very least, the library includes a collection of input and output subroutines. Sometimes the library also includes a variety of mathematical functions, because we have this (mostly bogus) idea that computers are about math. Many early computers were (and most modern computers still are) used for running a business with data and accounting and stuff like that, so libraries also tend to include one or more subroutines for sorting (the rest of the business activities tend to be too specialized for including pre-written in a library). Lately, with the increasing emphasis on computer graphics, libraries have a lot of useful tools (subroutines) for manipulating graphics on the computer screen.

Input & Output

Every programming language (not exactly including Chomp) has designated ways to get input in from the outside world and to display or save output for people to look at or other programs to get back in. Almost every modern programming language does this by means of specialized subroutines that come in the standard library for that language, but a few languages also have keywords to do common forms of output and (rarely) input. The tradition in C -- and the first Java program you will write -- is a single output "Hello, world!" onto the console log. But that's in the next lesson. Chomp lets you move the nibbler around and see and smell for pills, but that's all the input and output you get. Now we move on.

The point I want to make here today is that once you understand these six principles, and once you know how to spell them in any particular programming language, you can write any program in that language that anybody could write in any computer language. All there is left to learn is what the library of subroutines for that language offers pre-written for what you need to do.

So let's get started in Java...

  (ToC) Next >>

Begin Programming Page 9, 2020 March 21