Programming paradigms

There exists a multitude of different programming paradigms. This is due to the fact that different problems require different ways of thinking and here programming paradigms can help. Quite often programming languages reflect certain programming paradigms but modern languages often support a multi-paradigm approach and therefore we can use different styles in the language. This is the case for Python.

So far we have followed mainly the imperative model:

Note

In imperative programming, the code directly determines/controls the flow of the execution and explicit statements change the state of a program.

Imperative programming has a couple of subgenres that we will explore in time:

We introduce these concepts in the progress of this class where Object Oriented Programming has its own section.

A second model that is often used is call declarative:

Note

In declarative programming, the code declares the desired result but not how to compute it. It describes what computation should be performed without specifying detailed state changes.

The most common of these is functional programming where the concept of mathematical functions is used to declare the desired result as a series of function evaluations and it avoids state and mutable data.

We are also going to investigate the possibilities Python provides here in a dedicated chapter, functional programming, but list comprehension and recursion are some of the main features.

A comprehensive guide to these concepts can be found in Van Roy and Haridi (2004) and in the article Vasiliev (2022).