3. Programming as Communication

Key concepts

  1. Programming as communication
  2. Programs as communication artifacts
  3. The difference between "reading" and "understanding"
  4. The three world views: functional, operational, object-oriented simulation

Story

Programming is all about communication. First and most obviously, it is a precise way of communicating with a machine. To write a program is to tell a machine what to do. Second - and just as importantly - it is a way of communicating with other human beings. Why is the human communication element so important? First, very few programs are ever completely correct. That is, once they are put into production, errors are discovered. The program may not behave as expected. The person who fixes an existing piece of code may or may not be the person who originally wrote it. Second, programming projects, especially large ones, will suffer turnover of employees over the years. As new programmers come on board, they will inherit code that is years or even decades old, written by programmers who have long since moved on to other jobs. The new programmers will be charged with the task of reading and understanding this text. Finally, software evolves over time. The problem that a particular piece of software set out to solve a few years ago might be different today. For this reason, existing pieces of code often need to be modified to meet the new requirements of a different era.

Humans are incredibly good at "understanding" language, but very bad at "reading". For example, most people would have trouble reading the following:

I s ou r C hi l d r en le a r n i n g?

However, once you stare at the text long enough to realize that it asks, "Is our children learning?" you have no difficulty in understanding its meaning. Interestingly, despite the fact that it contains a grammar error, you still understand its meaning. Computers, on the other hand, are very good at reading. A machine would have no difficulty in picking out the sequence of letters in the above question, no matter how poorly they might be formatted. However, computers are extremely sensitive to grammatical errors, and would have great difficulty "understanding" the meaning of the above question. To communicate with a machine, we need to be incredibly precise in "meaning", but can be messy in our "writing." However, since humans will read the code as well, we need to write clearly too.

We'll rely heavily on three important metaphors when interpreting programs: a program as a precise set of instructions, programs as executable math, programs as simulation.

Operational world view

Traditionally, language has been viewed merely as a means of transferring information between two or more communicating parties. While language is certainly employed to transfer information, it has other uses too. Another view considers language as a means of effecting actions. Think about the following statement:

"Get me an gallon of milk (please)."
This statement brings about a whole chain of events, including causing you to get up, walk to the store, purchase a gallon of milk, and so on.

This action-oriented view of language is very applicable to computer programs. Programs are not merely about transferring information, rather, they command, instruct, cause things to happen. The program is a sequence of utterances that cause the computer to undertake one action or another.

Perhaps the best analogy is that of giving directions. Directions provide you with a sequence of steps, which, if you follow them, will get you to your destination. We call such a set of instructions an algorithm. Of course, the directions have to have a sufficient level of detail and precision to be meaningful to you. The sort of precision and logical thinking required to give a good set of instructions are skills you will cultivate over the course of your study.

Consider giving directions to the campus post office to someone familiar with the campus geography, such as a veteran student. Compare this to giving directions to a tourist. To the student, you might say:

"Walk just past the Union building and you'll see it on your right."
These instructions are of little use to the tourist however, because they assume a certain knowledge of the environment. For the tourist, directions such as the following are more appropriate:
"Walk under that arch and make a right. After about two hundred yards you'll see a red brick building on your left. That's the Union building. After you pass the Union, you'll see an ugly concrete building on your right, which is the post office."
The student understands a more expressive language for direction-giving than does the tourist. Computer scientists would say that the student is operating at a higher level of abstraction than the tourist. Abstraction, while it sounds complicated, just means focusing on the what rather than the how. It is a way of thinking about something that disregards the details of that things internal makeup or function.

When talking to the student, you can leave out many details, which you would have to perhaps explain to the tourist. Programming languages also allow us to express concepts at a variety of levels of abstraction. In fact, a large part of writing great programs consists of either leveraging existing abstractions or implementing your own abstractions appropriate to the task at hand. By implementing your own abstractions, you are in a way introducing new words (and their meanings) into the language, thereby allowing you to express instructions as a higher level of abstraction. Programming languages themselves may differ in the fundamental abstractions they present to the programmer. Java, for instance, tends to provide the programmer with higher-level abstractions than does, say, C.

Functional world view

Another powerful way to think about programs or pieces of programs is as a set of mathematical expressions that are evaluated to generate or calculate some sort of interesting result. For instance the following equation:

Area = PI x Radius2
expresses the area of a circle given its radius. We will see shortly that we can employ such expressions in computer programs. Almost all of our intuitions and experiences with mathematics can be applied to computer programs.

Object-oriented simulation world view

This view holds that programs are simulations of our world. They "model" the world around us. Hence, just like our world, they consist of animated objects that know things about themselves, can answer questions, and perform actions for us. Furthermore, we can construct simulations of "imaginary" worlds too. For instance, many video games suspend or modify the laws of physics and create a world unlike our own. And while spreadsheets resemble a piece of gridded paper, they are active in ways no piece of real paper will ever be.

In a way, this ability to construct simulations of imaginary worlds is one of the great things about writing computer programs. In many situations, it is much easier to build (and tear down, and experiment with) a simulation than it is to build the real thing. Programs are only plastic to an extent, however. Eventually, a program itself may become as complicated and hard to manipulate as real-world entities, because of the huge number of interactions between various pieces of the system. Remodeling the program becomes no simpler no simpler and no less without consequence than say, razing whole neighborhoods to build freeways. Finally, large-scale software systems do not and can not exist independently of the people who design, produce, test, and maintain them. Gross changes to the program structure will inevitably impact the social structure which has been erected to support it.


Ben Dugan & UW-CSE, Copyright (c) 2001.