Copyright © 2006 David Schmidt

Chapter 0A:
Introduction to Computing


0A.1 Computers can do lots of things, but they need programs to do them
0A.2 Programming = computer linguistics
    0A.2.1 Python
0A.3 Design: Software skyscrapers and software doghouses
    0A.3.1 How software is different from skyscrapers
    0A.3.2 Software architects, engineers, and programmers
0A.4 Foundations: Logical ways of thinking
0A.5 Organization of the chapters


First, read the Introduction chapter of Dawson.

When we compute, we calculate new knowledge. A program is a set of instructions (or laws) for computing --- for calculating new knowledge.

Computing science is about these things:

  1. linguistics: talking to the computer --- writing programs that tell the computer what to compute;
  2. design: talking to other people to design programs that are as complex as skyscrapers;
  3. foundations: thinking in a logical way to write programs, argue the correctness of the programs, and analyze their efficiency.
In a general sense, a ``computer'' is someone or something that can compute. So, if I study how to write good cook-book recipes, I am studying ``computing science,'' because a recipe gives instructions to a cook for ``computing'' someone's dinner.

Programming is the writing of programs --- --- it is ``speaking to the computer.'' A computer program is useful because a computer can ``read'' the program and follow its instructions even when we are not present. (It is like a cook making a recipe you wrote.) Of course, we must write the program in a language that both we and the computer understand, and much of this course will be concerned with learning such a common language.


0A.1 Computers can do lots of things, but they need programs to do them

It is amazing what computers can do. They show us web browsers that let us extract information from computers around the world; they display interactive video games that let us waste huge amounts of time; they are used by motion-picture animators to make entire motion pictures (e.g., Toy Story and Incredibles); they let a designer road test a car or airplane without constructing it; they can hold a model of the world's atmosphere (organized into cubic meters of air!) that simulates and predicts the world's weather. (A famous story: The computers owned by google.com hold a copy of every publically viewable web page on all the other computers in the world. When you search on Google, the search is made on Google's copy (its ``database'') of the world. The database is continuously updated.)

Computers can also model and mimic the behavior of biological organisms as well as compute the explosion and collapse of dying stars. These days, as many biology and physics experiments are conducted within computers as are done in real labs.

Computers also remember the exact balances of millions of bank accounts, credit card accounts, and alas, income tax bills. They have unfailing memories and arithmetic skills.

All of these computing activities are triggered by (incredibly complex and detailed) computer programs that people write. Without a program to read, the computer does not know what to do --- it is like a remote-control unit with no one around to press its buttons.

In this course, we focus on writing computer programs, and we emphasize programs that play games and do accounting, because these exercises give us skills that apply to most uses of computers. But we will not study how to build the computers themselves --- study computer engineering if you care about the ``hardware.'' (Computer programs are called ``software'' --- it is a bad pun that has stuck.)


0A.2 Programming = computer linguistics

Programming is writing instructions that a computer can do, can execute. Coding is the typing of the instructions into the computer. (The instructions are sometimes called code.) For the moment, forget about electronic computers---if your spouse (or a friend) can read and can operate an oven, then when you write instructions for baking a cake, you are ``programming'' your spouse --- the instructions are a program, and you are a programmer.

A program is a list of instructions written in a precise style where declarative verbs (``cut,'' ``pour,'' ``heat'') state computational actions, and nouns (``egg,'' ``flour,'' ``bowl'') state data with which computation is performed. Programs operate on data (ingredients); see Figure 1 for a program that ``computes'' a cake.

FIGURE 1: a program for making ``lemon cake''==============================

Ingredients:
      one lemon
      three eggs
      one cup of sugar
      two tablespoons of flour
      one cup of milk

Instructions:  
1. Squeeze the juice from one lemon into a large bowl.
2. Cut the lemon's rinds into small pieces and add them to the bowl.
3. Mix three eggs, one cup of sugar, two tablespoons of flour,
   and one cup of milk into the bowl.
4. Pour the mixture into a square cake pan.
5. Heat an oven to 350 degrees Fahrenheit.
6. Insert the pan into the oven and wait 40 minutes.

ENDFIGURE===============================================================

In the cooking example, the data was the ingredients, and the computer was actually the cook (and the oven). Computer programs use data that are words, numbers, sounds, and images, and the same principles for writing and executing cookbook recipes apply to computer programs as well.

If you are naturally talented at writing cooking recipes for others or at giving travel directions to others, then it is likely that you will readily learn how to write programs for computers. (If you have trouble writing recipes or directions, all is not lost, and this course will help you improve your thinking, planning, and communications skills.)

A computer program is almost always saved as a file on disk storage. When someone wants the computer to execute the program's instructions, the programmer starts the program, say, by clicking on the program's icon (its picture on the display) or by typing some text with the keyboard. The computer reads and does (executes) the instructions in the program.

Computer programs are not written in everyday English or French, nor in cookbook language. There are special languages, derived from algebra, that are used instead. Examples of such programming languages are Basic, C, C++, Fortran, Java, Lisp, ML, Prolog, Python, Scheme, and Smalltalk.

Computer languages are meant for communication, just like English, French, etc., are meant for communication. To communicate efficiently in a language, French, we must learn

  1. vocabulary: the language's words and what they mean
  2. grammar: the correct organization of words into meaningful phrases and sentences
  3. idioms: standard phrases and patterns used in conversation.
For example, in English, we learn words like ''go'', ''it,'' and ''how.'' We also learn that the words are grouped into categories like verbs, nouns, adjectives, adverbs, and conjunctions, so that we can assemble phrases and sentences, e.g., ''It goes.'' We also learn idioms, such as ``How's it going?'', which is somewhat surprisingly used as a greeting by some English speakers.

Programming languages also have vocabulary, grammar, and idioms, as we will learn.

Programming languages help us use computers in these ways:

In addition, the area of systems programming has developed to support the three groups above. Systems programming is the study of writing computer programs that help others write computer programs.


0A.2.1 Python

In this course, we will write programs in the language, Python. Python is a young language, but it draws upon decades of programming-design experience. It is designed to let us write useful programs simply and quickly, and it is also designed so that we can write programs that connect to pre-built programs written by others in the ``factory-programming languages'' of C, C++, Java, and C#. (This includes the C++ standard template libraries, the Java class libraries, and .NET, that is, basically everything that is in common use in the computing world.)

The skills we learn by writing Python programs will help us quickly learn how to write programs in other programming languages.


0A.3 Design: Software skyscrapers and software doghouses

Computer programs are written to tell computers amazing things. But as beginners, we must start small and work upwards to big things.

Building a complex computer program (computer software) is a complex activity, and the process of program building proceeds much like skyscraper design and construction. Here is a simplified description of how a skyscraper is built:

  1. The purchasers of a skyscraper meet with an architect (who is trained to design skyscrapers!) to discuss their needs for the building: how much space is needed, how many people will occupy it, what features and services the building must provide.

  2. The architect visualizes the form of building that will satisfy the purchasers' needs and designs the building. Many drawings and blueprints are made:

  3. Assuming that the purchasers are satisfied with the architect's work, the architect gives the drawings to a construction engineer, who calculates the physics of the building --- which materials and construction techniques are needed to construct the building as described by the diagrams. The engineer draws a set of construction diagrams that explain how to assemble the building so that it matches the architect's descriptions.

  4. Assuming that the construction engineer has calculated satisfactory construction plans, the plans are given to a construction team, who acquire the materials and build the skyscraper.

A complex computer program (like Windows XP or Mozilla Firefox or the latest n-dimensional video game) is developed in a similar way:

  1. The purchasers and users of the program meet with a software architect (or software designer) and describe what they want the program to do --- how the program should ``behave'' when they start it and use it and play with it.

  2. The software architect considers the form of computer program that can perform the desired behaviors and the architect draws several blueprints (called ``views'') that describe the program:

  3. Assuming that the software architect has assembed a satisfactory collection of diagrams, a software engineer (``lead technical person'') is consulted. The software engineer selects the programming language, programming data structures, programming techniques, and computer hardware that will be required to build the program.

    The software engineer writes a set of module specifications for the program pieces. The engineer (should also write) a set of protocol specifications for the communication properties between the program pieces. For some parts of the program, flowchart specifications are written.

  4. Assuming that the software engineer has developed a satisfactory set of specifications, the specifications are given to teams of software programmers, and the programmers build and connect the program pieces.

  5. Finally, programs are much more error prone than skyscrapers (although the latter are often built imperfectly), and programs undergo a period of testing, when people try using the program to verify that it behaves the way its purchasers want it.

So, building a ``software skyscraper'' is complex! But not all buildings are as complex as skyscrapers, and architects and construction engineers can have fun designing and building their own small buildings. For example, anyone with a few basic design skills, math skills, and construction skills can design and build a doghouse from beginning to end. A doghouse is small enough and simple enough that there are only a couple of simple blueprints to draw, only a couple of simple decisions about lumber and nails to make, and only a few simple construction tools needed to build the doghouse.

In a similar way, we can have fun making simple designs, learning programming techniques, and writing programs for our own ``software doghouses.'' In doing so, we will learn good habits and prepare ourselves for building larger programs in the future.

And don't be discouraged that this course starts with building software doghouses --- one person with a bit of experience can accomplish a lot of construction. I have a friend who spent few years on a house-construction team. Based on his experiences, he drew the blueprints, selected the materials, and constructed, almost entirely by himself, his own house! (It was a duplex, where each half was a two-bedroom house with a full basement. He did everything solo except for pouring the concrete foundation and raising the frame for the roof.) His project was a lot of work, but it went remarkably well --- the only mistake he made was not to leave enough room in the kitchen layout to allow his refrigerator door to open completely!

In a similar way, if you work hard, by the end of this course you will have enough skills so that you can design and build ''software houses'' that are surprisingly complex, comfortable, and fun.


0A.3.1 How software is different from skyscrapers

The analogy of software production to skyscraper construction is important, but the two products differ in a crucial way: software can be more readily altered than a skyscraper. Great care is taken when designing a skyscraper because there is little or no margin for error: once construction starts, it must finish as planned --- one cannot tear out one side of the building or remove a few floors after they are installed.

In contrast, software can be changed while it is being written, assembled, and tested; a big program piece can be removed and replaced by a different one, even after the entire program is built. Of course, there are time and cost penalties for such modifications, but there are no physical-material costs. This difference is both an advantage and a disadvantage:

If we return to the doghouse analogy, we can see that it is often OK for a person to start sawing lumber and pounding nails for a doghouse, even though there is not a precise blueprint for how the doghouse should look --- in the end, some sort of structure will be built, and the dog who will live in it will probably find it OK. In a similar way, when we write small programs for our own amusement, we can often start with simple sketches of the program structure and we can start writing the program, working on the design sketch and the actual program at the same time, and end up with a program that we find OK.


0A.3.2 Software architects, engineers, and programmers

As suggested by the above story, the computer software industry is populated by software architects, software engineers, and software programmers. This course, along with an undergraduate education in computing, is meant to direct you towards becoming a professional software engineer. (Advanced training and experience is required to be a software architect.)

But a good software engineer is also a good software programmer, and much of this course is oriented to developing your programming skills, by teaching you standard methodologies and patterns for programming. By the end of the course, you will also have exposure to software-engineering techniques, and you might also get a glimpse of software architecture at work.


0A.4 Foundations: Logical ways of thinking

The story about skyscraper building suggests that one must use methodical, step-by-step thinking to build a complex program. Step-by-step thinking is sometimes called ``logical thinking,'' because its use in formal logic and mathematics.

It is not an accident that you are encouraged to follow courses in mathematics and logic alongside courses in computing --- the courses complement each other and ``train your brain'' to think in a natural, efficient way to work in all three areas.

At the beginning of this chapter, we noted that computing is about calculating or synthesizing new knowledge, much like cooking is about synthesizing good things to eat. When a good cook follows the instructions of a recipe, he/she does taste tests from time to time to monitor the progress of the cooking. Indeed, a well-written recipe will contain ``taste checks'' that should be performed at certain stages of the cooking. If the reciple is followed correctly, the taste checks will turn out positively.

Here is another example, closer to the computer: When an electronics engineer designs an electrical circuit, the engineer draws a schematic diagram of the circuit and uses mathematics to calculate the levels of voltage, amperage, and resistance that should apprear on the wires of the circuit once the circuit is built and given electricity. The voltage and amperage calculations are both an analysis and a prediction of how the circuit should behave. When the circuit is built, its actual levels are measured with a multimeter and compared to the advance calculations; if there is a discrepency, this is a signal that some part of the circuit is faulty.

Here is an example schematic, of a vacuum-tube amplifier:


Notice that the wires to the vacuum tubes (the globes labelled V1 through V5) are labelled with appropriate voltages, and there is a table in the lower left corner of the schematic that lists the correct resistances that should be measured by the multimeter at each of the wires (``pins'') that connect to the tubes.

Rather than voltage or resistance, a computer program is a ``circuit'' that ``feeds on'' knowledge, and when we write a computer program, we should include ``knowledge checks'' that measure the amount of knowledge computed by the program at various stages of the computation. We will learn how to write and insert such knowledge checks, called assertions, into programs and use the laws of algebra to check that the assertions will hold true.

Here is an example computer program, drawn in circuit-schematic style. (This is a technical specification, called a flowchart.) The assert commands state levels of knowledge that are generated and maintained by the program when it is activated:


The fundamental ideas that underlie the design, the writing, and the analysis of computer programs come from a subarea of mathematics and logic, known as intuitionistic (constructive) mathematics. Formalized about 100 years ago, intuitionistic mathematics explains how one can formally describe a problem to be solved with symbolic logic, how to construct a solution using logical proof techniques, and how to analyze that the solution is correct.

Most software professionals are not expert in intuitionistic mathematics, but they use, unknowingly, the area's techniques within their everyday work. Although the instructor would truly enjoy presenting intuitionistic mathematics in this introductory course, practical issues demand that we take an informal, practical approach instead, and so we will.

Exercises

  1. Locate a cookbook and study one of its recipes. Mark the declarative verbs, nouns, and precise quantities. Also, circle any instructions in the recipe that appear to you to be imprecise.
  2. Arithmetic is often called the ``first programming language.'' Pretend that this expression is a program
    (3 + 2) - 1 + (6 + 5)
    
    and pretend that you are a computer. List the steps you take with your pencil to execute the instructions in this program. (That is, compute the answer to the expression, one step at a time.)
  3. Algebra is a programming language. List the steps you take to solve the value of x in this ``program'':
    3y - x = 3 + 2x
    
    (Hint: the first step is to add x to both sides of the equation, producing the new equation, 3y - x + x = 3 + 2x + x.)
  4. Here is a small fragment of a Python program:
     
    x = 3 + 2
    y = x + 1
    print y
    
    Which parts of this program appear to be verbs? nouns? adjectives? algebraic expressions?
  5. Propose a programming language for drawing colored bubbles and squares on a sheet of paper. What verbs will you include (e.g., ``draw,'' ``trace'')? nouns (``circle,'' ``red'')? adjectives (``large,'' ``dark'')?


0A.5 Organization of the chapters

At the beginning of this chapter, we noted that computing science includes
  1. programming linguistics: talking to the computer in a programming language;
  2. program design: designing programs that are as complex as skyscrapers;
  3. logical foundations: thinking in a logical way to write and analyze programs.
The tradition is to teach programming linguistics first and the other topics later. In these notes, we will use linguistics to introduce each topic, but we will also study the design aspects and foundational aspects of the topic --- sections labelled ``Design'' and ``Foundations'' will present the additional aspects. It is important that we see from the beginning how the three aspects of computer science depend on one another.