Skip to content

Programming fundamentals

~12 min

In short

Programming fundamentals are the small set of ideas that every later CS subject uses: values, types, variables, conditions, loops, functions, and reading errors. This page tells you what to learn first, what to leave for later, and where the Python course on this site covers each idea.

What the subject is about

A program is a list of instructions that a computer runs in order. Most of the work in a first-year programming course is about three things. You learn how to describe data (numbers, text, lists of values). You learn how to make decisions and repeat work (conditions and loops). You learn how to split a large task into named pieces (functions). Once you have these, you can read most code written by other people, even in languages you do not know yet.

The subject is not really about one language. Python is a good first language because its syntax is short and its error messages are readable. The ideas carry over to C, Java, JavaScript, and Go.

What to learn first

  1. Running a program, and what print and input do.
  2. Variables, the basic types (integer, float, string, boolean), and what a type error looks like.
  3. Arithmetic, integer division, and the order of operations.
  4. Comparisons and if, elif, else.
  5. while loops and for loops with range.
  6. Lists and dictionaries, and how to loop over them.
  7. Writing and calling functions with parameters and return values.
  8. Scope: where a variable is visible and where it is not.
  9. Reading a traceback from the bottom line upward.
  10. Reading and writing small text files, and catching an exception.

The site's Python course covers these in order. Start with ../../python/01-getting-started/index.md, then ../../python/02-decisions-and-loops/index.md, ../../python/03-data/index.md, and ../../python/04-functions-and-structure/index.md.

What you can skip at first

How it connects to the other subjects

Programming is the tool you use to test every other subject. When you study data structures and algorithms, you implement them. When you study databases, you send SQL from a program. When you study operating systems or networks, you write small programs that open files or sockets. A weak grip on loops and functions makes all of these slower.

Programming also gives you the vocabulary for the rest of this folder. Terms such as function, variable, and type appear in the glossary.

Free resources

  • The official Python tutorial (https://docs.python.org/3/tutorial/). Read it as a reference alongside the course. It suits anyone who wants the language's own description of its features.
  • CS50x, Harvard (https://cs50.harvard.edu/x/). A full first course in computer science with weekly problem sets. It suits someone who wants a structured class with deadlines and a community.
  • The Missing Semester of Your CS Education, MIT (https://missing.csail.mit.edu/). Covers the shell, editors, and version control that programming courses often assume you know. It suits anyone who gets stuck on the computer rather than on the code.
  • Teach Yourself Computer Science (https://teachyourselfcs.com/). A reading order, not a course. It suits someone who wants to know what to study after the basics.

Practice

  1. Write a program that asks for a name and a number, and prints the name that many times, one per line.
  2. Write a function is_even(n) that returns True or False. Then use it in a loop to print only the even numbers from 1 to 30.
  3. Given a list of marks, write code that prints the average, the highest mark, and the count of marks above 50. Do not use any library other than the built-ins.
  4. Take a traceback from a program you wrote with a bug. Write down, in your own words, the line that caused the error and the type of error. Then fix it.
  5. Write a program that reads a text file, counts the lines, and handles the case where the file does not exist.

Sources

  • Python Software Foundation, The Python Tutorial, https://docs.python.org/3/tutorial/
  • Harvard University, CS50x, https://cs50.harvard.edu/x/
  • MIT, The Missing Semester of Your CS Education, https://missing.csail.mit.edu/
  • Teach Yourself Computer Science, https://teachyourselfcs.com/