Computer Software from the Software Creator's Perspective


Algorithms and computational thinking

Computer programmers look at problems differently from most people. Faced with a problem, they think not just how to get an answer to this particular problem, but how to solve closely related ones. When asked whether there is a prime number between 300 and 310, the programmer asks himself or herself how to decide whether there is a prime number between any two given numbers m and n. They try to find an algorithm, which is a clear description of steps to use that will surely solve every such problem. Algorithms do not require subjective judgements. They should be spelled out so clearly that two different people, asked to follow the steps of the same algorithm, will end up with the same answer (assuming neither one makes a mistake in performing the steps).

I once read a story (presumably true) that illustrates how computer programmers think. The individual telling the story was applying for a security clearance. One of the questions on the required form asked for the person's race. After thinking about the issue, this individual reached two conclusions. First, he could not come up with an algorithm that would take data about an arbitrary person's ancestry and give a reasonable answer to the question, "what is your race?" Second, he was sure that, even if he could come up with such an algorithm, he did not have enough data about his own ancestry to be able to carry out the necessary computations. Given this quandry, he wrote in "mongrel".

Shortly after submitting his application, he received a call asking him whether he meant "mongol". No, he said, its mongrel. In short order he received a visit from people checking on him, who concluded he was a bit odd but not a security risk. He got his clearance in record time.


Programming languages

Of course, we do not really want people to perform the steps of our algorithms. That's why we have computers. But to get a computer to perform an algorithm, we need to express it in a form that the computer understands.

A programming language is a notation used to express an algorithm. When you express an algorithm in a programming language, what you get is called a program.

There are a lot of different programming languages. Software called compilers convert programs written in various programming languages into step-by-step instructions for a particular processor. So you write your program in the language of your choice and then use the compiler to translate it into a form that can be understood by the processor.


Simplicity and elegance

If a problem can be solved by an algorithm, then it always has many different algorithms that will do the job. Some might be short and simple while others are long and complicated.

Programmers have found that, in general, short and simple algorithms tend to work correctly. On the other hand, long and complicated algorithms often contain mistakes in details, even if the general idea is right. And the details matter a lot. The more complicated your algorithm is, the longer it will take you to get rid of all of the mistakes in it.

In this course, we will emphasize trying to find simple and elegant algorithms for problems, staying away from unnecessarily complicated ways of doing things.


Dealing with mistakes

No programmer is perfect. They all make mistakes. You can count on making many yourself, and you will be surprised at how many mistakes you make.

The way to deal with this is to accept that you are fallible. If make a mistake, do not let it upset you. But your attitude should be that you want to end up with a high quality, mistake-free program in the end. So you find and fix your mistakes.

You can reduce (but not completely eliminate) the number of mistakes that you make, and the amount of time you spend fixing them, by working problems out carefully. We will go through examples of how to do that. It will be up to you to take the methods that we cover to heart and follow them. You will have much better results if you do.

A good computer programmer has an eye for detail. Look carefully at what you write. Proofread it. Avoid being sloppy. Do not write y where you mean x.


Problems

  1. [solve] What is an algorithm?

  2. [solve] What is a programming language?

  3. [solve] What is a program?

  4. [solve] What is a compiler?

  5. [solve] Why is simplicity and elegance of algorithms or programs important?


Summary

An algorithm is a clear and unambiguous set of instructions for solving a certain kind of problem.

When you encounter a problem, think about it computationally. That means asking yourself not just how to solve that particular problem, but how similar problems (maybe with different numbers or other data) can be solved by clear and unambigous instructions.

It is a good idea to strive for simplicity and elegance when creating software.