So, writing a computer program can be like composing music, like building a house, like creating lots of stuff. It has been argued that in its current state, it is an Art, not engineering.
An important reason to consider learning a bit about how to program a computer is that the concepts underlying it will be valuable to you, regardless of whether or not you go on to make a career out of it. One thing that you will learn quickly is that a computer is very dumb. It does exactly what you tell it to do, which is not necessarily what you wanted. Programming will help you learn the importance of clarity of expression.
A deep understanding of programming, in particular the notions of successive decomposition as a mode of analysis and debugging of trial solutions, results in significant educational benefits in many domains of discourse, including those unrelated to computers and information technology per se. (Seymour Papert, in "Mindstorms")
Computers have proven immensely effective as aids to clear thinking. Muddled and half-baked ideas have sometimes survived for centuries because luminaries have deluded themselves as much as their followers or because lesser lights, fearing ridicule, couldn't summon up the nerve to admit that they didn't know what the Master was talking about. A test as near foolproof as one could get of whether you understand something as well as you think is to express it as a computer program and then see if the program does what it is supposed to. Computers are not sycophants and won't make enthusiastic noises to ensure their promotion or camouflage what they don't know. What you get is what you said. (James P. Hogan in "Mind Matters")
But, most of all, it can be lots of fun!!!
But, since you are going to learn how to write computer programs, you need to know a little bit about how a computer works. Your job will be to instruct the computer to do things. These lists of instructions that you will write are computer programs, and the stuff that these instructions manipulate are different types of objects.
Basically, computers perform operations on objects. A microprocessor, which is the heart of a computer, is really primitive but very fast. It takes groups of binary numbers representing parts of objects and moves them around, adds pairs together, subtracts one from another, compares a pair, etc... - that sort of stuff.
Computers manipulate numbers, symbolic information (think characters), visual things (images), sound (heard of MP3?), and sets of instructions (the computer's native language).
As an example, computer displays consist of a bunch of colored points
called pixels. A pixel is an object. It has a position which
consists of the row and column it is in. Its color is specified as
three numbers - called RGB (Red, Green, Blue) values. Play with the
following Java applet which lets you see what number values generate
which colors. What color do you get if you set red to 170, green to
85, and blue to 255? What's the RGB value for your favorite color?
Color Numbers Applet
So, like pixels are used to compose graphics and images, there are also standard representations for the other things: numbers, characters, sound, and the computer's instructions. At the lowest level, they everything is a bunch of ones and zeros!
There are only 10 different kinds of people in the world: those who know binary and those who don't. - Anonymous
As you explore how computers work, you'll hear more about numbers expressed in octal and hexadecimal; these are just more manageable representations of binary information. Table 1.1 shows some numeric and symbolic values for you to check out...
|Numeric and Symbolic Information|
|Numeric Information||Symbolic Information|
Just like we have many different languages in use throughout the world for us humans to communicate with, there are different languages that we use to communicate with a computer. Computer languages are used to tell the computer what to do, you instruct it.
If you instructed a computer in its native language (machine language), you would have to write instructions in the form of (yes, once again) binary numbers. This is very, very hard to do. Although the pioneers of computers did this, no one does this these days.
One step above machine language is assembler language. In assembler, the operations that the microprocessor knows how to do are given names. Addresses in memory can also be given meaningful names. This is a big step over binary, but still very tedious to do any large software program with. It still has its place for little pieces of software that need to interact directly with the microprocessor and/or those that are executed many, many, many times. Table 1.2 is an example of DECsystem-10 assembler language that:
In this introduction to programming, you will work with two computer languages: Logo and Java. Logo comes from Bolt, Beranek & Newman (BBN) and Massachusetts Institute of Technology (MIT). Seymour Papert, a scientist at MIT's Artificial Intelligence Laboratory, championed the computer programming language in the 70s. Java is one of the newest programming languages. It appeared in 1995 just as the Internet was starting to get lots of attention. Java was invented by James Gosling, working at Sun Microsystems. It's sort-of a medium-level language.
With Logo, you will be able to write computer programs quickly and easily since it is a very simple language. Once you have some experience with it, you will move to writing programs in Java.
One of the advantages of learning Java is that there is a lot of software already written which will help you write graphical programs that run on the Internet. You get to take advantage of software that thousands of programmers have already written. So, you are not limited to working with numbers and characters; you get to work with window objects, canvas objects, string objects and thousands of others. You will not be limited to simple operations like adding two numbers; you will use operations like create a new window, draw a line, display some text in a window, and much, much more.
Remember what I said in the Introduction to this lesson?
Writing software, computer programs, is a lot like writing down the steps it takes to do something.
Before we see what the Logo computer language looks like, let's use the English language to describe how to do something as a series of steps. A common exercise that really gets you thinking about what computer programming can be like is to describe a process you are familiar with.
Rather than write my own version of this exercise, I searched the Internet for the words "computer programming sandwich" using google. One of the hits returned was http://teachers.net/lessons/posts/2166.html. At the link, Deb Sweeney (Tamaqua Area Middle School, Tamaqua, PA) described the problem as:
Objective: Students will write specific and sequential steps on how to make a peanut butter and jelly sandwich. Procedure: Students will write a very detailed and step-by-step paragraph on how to make a peanut butter and jelly sandwich for homework. The next day, the students will then input (read) their instructions to the computer (teacher). The teacher will then "make" the programs, being sure to do exactly what the students said...This lesson is excellent at demonstrating how careful you need to be, how detailed you need to be, when writing a computer program.
Application-Specific Language (4GL)
Examples: Mathematica, SQL
Examples: Logo, Smalltalk
Example: Intel X86
1100 + 1010 ------Now let's add them together.
1100 + 1010 ------ 10110
For a second problem, let's just swap the ones and zeros. Solve this one as a group...
0011 + 0101 ------Now your turn. Write down the steps you've used, generalized for adding ANY two binary numbers together. I'll get you started.