Tutorials: Functional Python

Presented by:


Description

Python supports multiple programming paradigms. I addition to the procedural and object-oriented approach, it also provides some features that are typical for functional programming.

While these features are optional, they can be useful to create better Python programs. This tutorial introduces Python features that help to implement parts of Python programs in the functional style. Objective is not to write pure functional programs but improve programs design by using functional feature where suitable.

The tutorial points out advantages and disadvantages of functional programming in general and in Python in particular. Participants will learn alternative ways to solve problems. This will broaden their programming toolbox.

Software Requirements

You will need Python 3.9 installed on your laptop. Python 3.7/3.8 should also work. You may use Python 3.10 if is released at the time of the tutorial and all dependencies can be installed.

JupyterLab

I will use a JupyterLab for the tutorial because it makes a very good teaching tool. You are welcome to use the setup you prefer, i.e editor, IDE, REPL. If you also like to use a JupyterLab, I recommend conda for easy installation. Similarly to virtualenv, conda allows creating isolated environments but allows binary installs for all platforms.

There are two ways to install Jupyter via conda:

  1. Use Minconda. This is a small install and (after you installed it)
    you can use the command conda to create an environment:
    conda create -n pycon2021py39 python=3.9
    Now you can change into this environment:
    conda activate pycon2021py39. The prompt should change to (pycon2021py39).
    Now you can install JupyterLab: conda install jupyterlab.

  2. Install Anaconda and you are ready to go if you don't mind installing
    lots of packages from the scientific field.

  3. Install the dependencies:

    * Jupyter Lab 2 conda install jupyterlab
    * more_itertools conda more_itertools
    * toolz conda install toolz

  4. Hint: You do all this in one command:
    conda create -n pycon2021py39 python=3.9 jupyterlab more-itertools toolz

You can create a comparable setup with virtual environments and pip, if you prefer.

Working witch conda environments

After creating a new environment, the system might still work with some stale settings. Even when the command which tells you that you are using an executable from your environment, this might actually not be the case. If you see strange behavior using a command line tool in your environment, use hash -r and try again.