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:
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.
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.)
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
Programming languages also have vocabulary, grammar, and idioms, as we will learn.
Programming languages help us use computers in these ways:
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.
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:
A complex computer program (like Windows XP or Mozilla Firefox or the latest n-dimensional video game) is developed in a similar way:
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.
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.
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.
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.
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.
(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.)
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.)
x = 3 + 2 y = x + 1 print yWhich parts of this program appear to be verbs? nouns? adjectives? algebraic expressions?