Overview

In the following, we introduce the fundamentals of programming. We use Python as a programming language. However, most of the concepts we present can also be found in many other higher programming languages. The topics discussed are data types, control flow, functions, Input and Output (I/O), and Object-Oriented Programming (OOP). Some preliminary hints before we get started:


Code Layout

The programming language we use here, Python, is whitespace sensitive, i.e., indentation carries meaning. We will see many examples in the following sections. In brief, whitespace sensitivity means:

  • all lines in a code block need to be aligned;
  • for a code block to end, its indentation must end as well;
  • several nested blocks of code need to be indented systematically on multiple levels.

For some programs, it makes a difference whether we indent with tabs or with spaces (regardless of whether our code looks aligned for us humans). The official recommendation is to use four single spaces to indicate one level of indentation, however, using one tab might be more comfortable in everyday practice. Bottom line: whatever option you choose, be consistent.

Whitespace sensitivity allows Python to express meaning with a minimum number of braces. Programming languages that are not whitespace sensitive (e.g., Java) frequently use curly braces ({}) instead of systematic indentation - and still recommend systematic indentation to improve legibility.


Terminology

Computer programs contain statements designed to be executed by a computer. A statement is composed of one or more expressions that can be evaluated by the computer. Expressions can return values, which are associated with certain data types. All expressions are composed of literals, variables, and functions.

Generally, variables can be declared (variable declaration) and assigned values (value assignment). In Python, variable declaration happens by value assignment (variable = value), whereas in some other programming languages, variables can (or even must) be declared before they are assigned values. Once we have declared a variable, its name becomes part of the namespace of the executed program. Therefore, we can use the name of a variable to access its current value.

Which variable names are allowed, and which are recommended?
See Python's naming conventions for answers.

Some popular functions have received special syntax constructs - not only in mathematics but also in many programming languages. These syntax constructs are called operators. Among the most important operators are the arithmetic operators (e.g., + to denote addition) and the Boolean operators, which are introduced in the section on control flow.

The terminology used to refer to basic programming concepts is very heterogeneous. Most of the time, you'll be able to to infer its meaning from the context. The terms introduced above are particularly suited to describe programs that follow the programming paradigm of imperative programming. An overview of the common programming paradigms can be found here.


results matching ""

    No results matching ""