Sketch of a programming curriculum
Status: In progress
Confidence: Very likely
This is a guide and a set of exercises to getting the very basics of programming down. You will need to search the Internet to learn how to solve the exercises in whichever language you choose, but they are a good starting point.
Pick a language
Programs are written in various different languages. Exactly which language you learn in doesn’t matter very much. If you don’t want to deal with walls of text, consider Scratch. Otherwise,if you don’t have any reason to choose differently, Python is a not-wrong answer. If you want to be really esoteric, you could try Oberon.
Learn how to add two numbers in the language you picked. Read your language’s documentation and search the Internet to figure out how to write an expression in the language and how to get the computer to evaluate it and give you the answer.
Numbers are single terms in a language. There aren’t subpieces of a number. We call this kind of thing atomic (that is, it cannot be split). There are other atoms in languages, such as characters, or true and false. Find some other types of atoms in the language you picked and write some expressions with them.
Insert the notion of types here, and how they are represented in memory? That they are all binary patterns.
- Add two numbers.
- Subtract two numbers.
- Calculate the average of five numbers.
- Append one piece of text to another (pieces of text are usually called strings).
- Calculate the length of the hypotenuse of a triangle using the Pythagorean theorem.
- Convert a temperature from Farenheight to Centigrade.
Often we will want to give a name to some intermediate state in a program. We do this by creating a name called a variable in the program that we can use anywhere we would use the value we set it to. Look up how to define variables in your language.
- Calculate the square of two sides of a right triangle and assign them to variables, then sum and take the square root of them to calculate the hypotenuse of the triangle.
- Assign the constants in converting from Farenheight to Centrigrade to variables and rewrite your expression to use them in place of the numbers.
Using our computer as a calculator isn’t very exciting. To go farther, we need to be able to extend it with new things we can do. We do that by defining functions. Functions encapsulate a set of steps and can perform them on different inputs to produce outputs.
In your language, read how to define a function.
- Write a function that takes a temperature in Farenheight and converts it to Centigrade.
- Write a function that takes the length of two sides of a right triangle and returns the length of the third side using the Pythagorean theorem.
- Write a function that averages three numbers.
(Concern: what generic exercises would introduce scope usefully?)
The structure “if X then Y else Z” is ubiquitous in programming. It lets programs behave differently depending on their inputs.
Look up how to do a conditional (sometimes called an “if statement”) in your language.
- Write a function that returns true if a number of positive and false otherwise.
- Write a function that returns the absolute value of a number.
- Write a function that returns if its first argument is greater than its second.
- Write a function that returns true if a string (a sequence of characters) is not empty.
Variables, conditionals, and functions are the patterns of working with fixed numbers of atoms. Next we consider what to do when the number varies.
Looping over lists
Lists (or their cousin, arrays) contain a sequence of values. It can be zero values. It can be one, or two, or thirty six. The values can be atoms, or other lists.
Look up how to make lists in your language.
- Make an empty list, a list containing a couple of numbers, and a list containing several lists of numbers.
- Append a value to an existing list.
- Learn how to fetch individual elements, such as the first or third element, from a list.
Unlike for fixed numbers of values, we need a new construct to be able to deal with lists. This construct is called a loop, and it repeats a fragment of program for each value in the list. Look up how to write a loop in your language.
Example functions to write: - Sum a list of numbers. - Sum all the even numbers in a list. - Calculate the length of a list. - Return a new list containing only the even numbers in a list of numbers. - Take a list of lists and return a new list containing the length of each list in the original list. - Concatenate two lists. - Concatenate a list of lists.
At this point you have all the basic constructs of structured programming: variables, conditionals, loops, and functions. These are the fundamental tools that most of your programs will be made of.
- Input and output: Your programs need to interact with the outside world.
- Abstract data types: You can create new types of values to manipulate.
- Dictionaries, Trees, and Graphs: There are more things we can loop over after abstract data types
- Program correctness: You need to demonstrate that your program works properly.
- Explore some very different different languages.
Input and output
There are four main channels that your program will use interact with the outside world:
- Reading and writing files on the disk.
- Communicating with other programs on the same machine.
- Communicating with other computers over a network.
- Communicating with a human via a user interface (displaying images to a screen, playing sound, receiving input from keyboards, mice, joysticks, etc.).
Abstract data types
Dictionaries, trees, and graphs