First steps (Part 1)

Why learn programming?

Welcome. Let's start by addressing some questions that you might have. You might be asking, "Why learn to communicate with a machine?" The answer depends on you.

Some areas of applications of programming.

Images (clockwise from top left): pots -- Ilka-Erika Szasz-Fabian/iStock/Thinkstock;
TV -- scyther5/iStock/Thinkstock; bread -- MikeyGen73/iStock/Thinkstock;
ultrasound -- Nerthuz/iStock/Thinkstock; Earth -- leonello/iStock/Thinkstock;
telescope -- Nerthuz/iStock/Thinkstock

I've written programs for converting bread recipes, calculating volumes of soil needed for seedlings, and helping doctors plan treatment of patients. Depending on your interests, you might use a computer to model the spread of epidemics, create images for games or movies, or solve problems in astronomy.


What if I do not know my plans?

Even if your future use of computers is hard to predict, this course will provide you with a solid foundation. No matter what your goals are, the starting point is the same. We will cover the basics, step by step.


What if I buy programs instead of writing them?

You can benefit from this course even if in the future you end up using others' programs instead of writing your own.

Two images: a gear shift, and an image depicting planet Saturn as a basketball.

Images: (left) Vlad Kochelaevskiy/iStock/Thinkstock; (right) Ivor Traber

After all, you don't have to be an auto mechanic to benefit from knowing what a gear is. Even if you are a basketball player and not a physicist, it helps to understand gravity.


What is a program?

You can think of a program as a to-do list for your computer or phone. More precisely, it is a list of instructions written in a programming language.

A program is a list of instructions for a computer.

Machines (computers) see a flower as a sequence ofthe digits 0's and 1's.

Images: (left) Ryan McVay/Photodisc/Thinkstock; (right) Gunnar Pippel/Hemera/Thinkstock

This requires finding a way to translate between the ideas of flexible, intuitive, poetic humans, who see a flower with all its colors and exquisite details, as shown by the sunflower in the figure, and precise limited machines, who see a flower as a sequence of 0's and 1's, as shown by the rightmost figure.

Don't worry, you are not going to be asked to translate flowers into sequences of 0's and 1's


What is a programming language?

A programming language is the half-way point between an idea and a machine language.

Ideas are written in a computer language before automatic tools translate them to machine language.

Images: (left) urfinguss/iStock/Thinkstock; (right) thumb/iStock/Thinkstock

There are automatic tools to translate between a programming language and a machine language, so the interesting part is translation from an idea to a programming language.

A program is written in (source) code.

Since something written in a programming language is called "code", this process is called "coding".

Writing a program is coding.


Do I need to think like a computer?

Does this mean thinking like a computer? When you speak to a baby, do you need to think like a baby? No!

Two images: a baby and a computer.

Images: (left) Chris Boswell/iStock/Thinkstock; (right) Madmaxer/iStock/Thinkstock

But you do need to understand how a baby thinks. The challenges faced in communicating with a computer are not due to your limitations as a human, but rather to the limitations of the computer as a machine.


What are the limitations of a computer?

  • A computer executes simple steps.
  • A computer has limited storage space.

A computer might seem smart, but it is only because it is fast. It can execute simple steps very quickly. So your job is to break down tasks into simple steps. Another limitation is that a computer has a finite amount of storage space. This becomes obvious when you run out of space to store music on your phone or computer. What is less obvious is what happens when you store a number like pi, which has an infinite number of digits after the decimal point.

The number Pi has an infinite number of digits and only a finite number of digits are stored.

Only a finite number of digits can be stored as an approximation of the original number, called a floating point number.

A floating point number may be an approximation.

Knowing that numbers are approximate makes behaviour a little less surprising.


How do I translate ideas into code?

Remember, a computer executes a sequence of steps. None of the individual steps on their own are that impressive or surprising. What makes computers so useful is that each step can be accomplished very quickly. Just like you might write down an outline before writing an essay, programmers often jot down steps using pictures, diagrams, or pseudocode.

Programmers often write down steps using pictures, diagrams, or pseudocode.

Image: urfinguss/iStock/Thinkstock

Pseudocode is a compromise between English and all code.

Pseudocode can be seen as a half-way point between ideas and most programming languages. Since pseudocode is read by humans instead of computers, it tends to have less punctuation and more full, understandable words, like "define" and "return" in this example. The hard part of the translation is between an idea and pseudocode, but fortunately we only have to do it once for all programming languages. Translations between pseudocode and programming languages are similar, so once you've learned to do this once (by learning one language), it is much faster to learn other languages. As the same basic ideas appear in almost all languages, which language you learn first isn't that important.


How is it like learning a human language?

In some ways, learning a programming language is like learning a human language.

  • Practice, practice, practice!
  • Different languages require different ways of thinking.
  • Pay attention to syntax (correct "grammar") and semantics (meaning).

The most important similarity is that lots of practice is the key to success. It is also a good mental exercise: it gets you to think carefully about how you express yourself. There are rules about how to write correctly, and rules about how to interpret the meaning of what is said.


How is it different from learning a human language?

So how does learning to program differ from learning a human language?

Learning a computer language is unlike learning a human language

Images (clockwise from top): baby -- Chris Boswell/iStock/Thinkstock;
woman -- Hemera Technologies/PhotoObjects.net/Thinkstock;
ball -- grandeduc/iStock/Thinkstock; M'emorial Gor'ee-Almadies -- Ivor Traber

There are no native speakers, so you can't learn it as a baby from your parents. You can't practice it by watching a movie or going on holiday to another country. Don't expect the listener to understand when you throw in a few words of your own language or get the grammar a bit wrong. And acting out your meaning is not going to help.

Dealing with such an unforgiving conversational partner might seem like a nuisance. And it can be. But the benefits are enormous, as you learn to express yourself clearly and precisely and get the computer to do work for you.


Puzzling it out

Programming is like solving a puzzle

Images: Nahhan/iStock/Thinkstock

  • Programming is like solving a puzzle.
  • Learning from your mistakes is part of the learning process.
  • Practice is the key. The more you do, the better you get at it.

Why is the course called "from scratch"?

The term "from scratch" is used because it means that we are starting from nothing, assuming you have no background in programming. Here the goal is not to get to the solution as quickly as possible, like cutting corners by using a "cake mix", but instead to take the time to understand each ingredient, so that you have the skills necessary to create whatever you like in the future.

Starting from scratch

Images: (left) Radu Razvan/iStock/Thinkstock; (right) theospoint/iStock/Thinkstock

You will not be asked to do something without first understanding it: explanations will be followed by demonstrations, and lots of hands-on exercises, including experimentation and learning from mistakes