Berkeley Foundation for Opportunities in Information Technology

Introduction to Programming

What Is Computer Programming?


*Note*    In 2007, these lessons were significantly modified.    *Note*
This is a link to the new materials.
This is a link to the new first lesson.


Introduction

Writing software, computer programs, is describing how to do something.   In its simplest form, it is a lot like writing down the steps it takes to do something - a process.  But, if what you need to do is not obvious or it involves multiple objects (each with their own process) writing the program will challenge you like when you are solving puzzles. 

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!!!


Inside Computers - All Ones and Zeroes

Today, most people don't need to know how a computer works.  Most people can simply turn on a computer or a mobile phone and point at some little graphical image on the display, click another button, and the computer does something.  An example would be for it to get weather information from the net and display it.  This is all the average person needs to know about using a computer (or any device that's computer based).

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?

alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." Your browser is completely ignoring the <APPLET> tag!
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!


Binary Representation of Stuff

There are only 10 different kinds of people in the world:
those who know binary and those who don't.

                                              - Anonymous 
Computers are full of zillions of binary numbers, i.e., lots and lots of 1s and 0s.  In fact, there are so many and it takes us humans so long for us to manipulate them that we group bunches of binary numbers together to makes things easier.  As an example, the letter 'A' in a computer has the binary representation: 01000001.  But, when we express this as an octal number, where three binary ones/zeroes are grouped together to form an octet, 'A' is 101.  101 is much easier to read, write, and manipulate than 01000001. 

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
Decimal
Number
in
Binary
in
Octal
in
Hexidecimal
1
1
1
1
2
10
2
2
3
11
3
3
4
100
4
4
5
101
5
5
6
110
6
6
7
111
7
7
8
1000
10
8
9
1001
11
9
10
1010
12
A
11
1011
13
B
12
1100
14
C
13
1101
15
D
14
1110
16
E
15
1111
17
F
16
10000
20
10
ASCII
Character
in
Binary
in
Octal
in
Decimal
in
Hexidecimal
space
00100000
040
32
20
!
00100001
041
33
21
(
00101000
050
40
28
)
00101001
051
41
29
0
00110000
060
48
30
1
00110001
061
49
31
2
00110010
062
50
32
3
00110011
063
51
33
A
01000001
101
65
41
B
01000010
102
66
42
C
01000011
103
67
43
D
01000100
104
68
44
a
01100001
141
97
61
b
01100010
142
98
62
c
01100011
143
99
63
d
01100100
144
100
64
Numeric Information Symbolic Information
Table 1.1


Programming Languages (The Microprocessor's Language)

So, what is a programming language?

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:

  1. adds two numbers together,
  2. adds in a third number if it is greater than zero, and
  3. stores the result in a third location.
 OpCode Accumulator  Operand
  MOVE   T1   number1  
  ADD   T1   number2  
  SKIPLE     number3  
  ADD   T1   number3  
  MOVEM   T1   result  
Table 1.2


Programming Languages (High-Level Languages)

Most software written today is written in high-level languages.  There are many and some are quite old.  COBOL, FORTRAN, and Lisp were written in the 1950s!!!  Higher-level languages make it easier to describe the pieces of the program you are creating.  They abstract away the specifics of the microprocessor in your computer.  Most come with large sets of common stuff you need to do, called libraries.

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.

Programming Using the English Language

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.

Describe how to make a peanut butter and jelly sandwich.

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. 


Hierarchy of Computer Languages

  Application-Specific Language  (4GL)
Examples: Mathematica, SQL
High-Level Language
Examples: Logo, Smalltalk
Low-Level Language
Example: C
Assembler Language
Example: Intel X86
Table 1.3


Exercise

I want to combine exposing you to more details about how a computer works and the "programming in english" lesson.  Let's learn more about binary numbers.  Get a piece of paper and write the following binary addition problem on it:
        1100
      + 1010
      ------

Now let's add them together.
  1. The first column, 0 + 0 = 0; is easy.
  2. The second column, 0 + 1 = 1; that's easy too.
  3. The third column, 1 + 0 = 1; this is cake...
  4. The fourth (last) column, 1 + 1 = 2; NOPE... We don't have a 2 in binary numbers. 2 is written as 10, which is a zero with a carry of 1. Since this is the last column we're adding, we just write in the 10.
        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.

  1. Start with the rightmost column.  If both of the numbers are zeros, write a zero underneath them and go on to work on the column to the left of the current column.
  2. If one of the numbers is a one and the other is a zero, write a one and go on to work on the column to the left of the current column.
  3. ?...



Back to Table of Contents
On to next Lesson ( Introductory Logo Commands )


      

Watch a short video that shows what BFOIT is doing...

Berkeley Foundation for Opportunities in Information Technology