An introduction to programming
I have been thinking about trying to teach my kids some programming. There are programs like Alice, but the kids didn’t like that. A lot of PhDs have been earned while working on Alice, but I think it is an adults idea of what kids can understand, not a kids idea of it.
The problem, as I see it, is that after working in the field for a while, we adopt the vocabulary and syntax of the field and it is a high bar for newcomers to cross. I thought about how I became interested in computers and it was a brute force, immersion approach. The daughter of a friend of mine is at the U of Washington as an electrical engineering student and she has a team project to build and program a robot. I don’t think she has had any programming instruction at this point. Someone else in the team will do that work.
I am going to use this page to develop an approach to programming.
What is a programming language?
A programming language is a set of rules that allows a programmer to control a computer system in a more human friendly way. The rules may include, but are not limited to, rules on the use of key words, operators and operands.
Keywords, operators, operands? What are those?
Some words have specific meanings in a computer language. We call those words keywords. Operators and operands are like verbs and nouns in a regular language. The way an operator operates on an operand is particular to the language.
To the language? How many languages are there?
Too many. Okay, that is too glib. People have been creating computer languages for a long time for whatever purpose they have at hand. Sometimes, they need features that are not available in a particular language, so they create a language for that.
Like what?
Well, let’s say that you had a telescope that you wanted to control. The people who would need to control it don’t have a lot of experience in programming, so a very simple language that lets the user start up the telescope, enter stellar coordinates, adjust the focus, record settings and then shut down the telescope would an example of that kind of language.
Oh. But the keywords are all the same, right?
No, but close. There are many constructs that we use in programming that are common across languages. When you have been programming for a while, it will be easier to understand these.
Okay, that is as clear as mud. Can you give an example of the kinds of rules you are talking about?
Yes, I can give you some examples, but before I do that, I think I need to put out some other information. First, no matter what programming language you use, no matter what system you use, a computer is going to operate and execute two kinds of logic: combinatorial and sequential. Combinatorial, the combining of things, and sequential, one thing after another, are the heart of all logic operations. An example of combinatorial logic is “if I get my homework done in 30 minutes and Dad thinks I have done a good job, then there will be time for computer games before bed”. An example of sequential logic is “the bread will be ready to bake if the oven has warmed enough and the bread, wihch I put in the sunny spot by the window, has risen enough”. The difference between the two is that sequential logic has a sense of time associated with it; the result is determined by some new information and some retained information.
That sounds like a lot of fuzzy hand waving.
Well, I mentioned it because one important thing that progamming languages do is provide for data storage and retention. Information may be stored and used later.
Oh. What kind of data?
Well, what kind do you have? One of the things that separates programming languages is how they name and classify data. So I think we will not get into the specifics of that right now. We’ll take that a little bit at a time.
So there is data. Operators? What’s an operator. You said it was like a verb.
Yes. Some operators you already know, like ‘+’ and ‘/’. We use those on numbers in programming languages in the same way that you use them in math. There are other operators, but they often use symbols that are particular to the language. For the time being, we’ll only use the operators that you know from math.
Okay, so we have data, operators and what else?
Keywords.
I suppose now you are going to go into a long explanation of what a key word is.
Hey, give me a break. I spent a lot of time studying this stuff. I want to show off a little. Keywords are the words we use from our natural language to describe common tasks.
Common tasks?
Yes. For example, let’s say that you are in a store and have a carton of eggs and you want to see if any of them are cracked before you buy the carton. You open it, and then pick each egg up and look at it, looking for broken eggs. As a human, we can see all the eggs and we may have a pattern we used to make sure we look at each egg at least once, but a computer doesn’t do that easily. The easy thing for a computer is to think of the eggs in a single row and look at each one in turn. This kind of thing is called a loop, and many languages use the word ‘for’ with this kind of loop because if you described what you are doing, you would probably use the word ‘for’. Like this: starting at the first egg, look at each egg, checking for cracks or holes; if you find one, put the box of eggs back and try another one. Hmmm, I didn’t use the word ‘for’. Okay, you’ll have to trust me on that one. Maybe it is like how ‘inflammable’ and ‘flammable’ have come to mean the same thing. When I think about this, I think “for egg_position = 1; while egg_position is less than 12; increment egg_position” A for loop has an initialization part, a termination part and a part that is used to step though the items. There is also a ‘while’ loop construction that is a little different. For example, let’s say you were working in a factory, and your job was inspecting eggs. You would work by a moving belt of some kind and look at each egg that came by until there were no more eggs or you took a break. That would be something like, “while there are eggs and it isn’t time to go on break, inspect eggs”.
Computer programming languages have if-then-else and looping constructions along things to specify kinds of data.
——————–