abstractions-in-python

Introduction

This is the online textbook Programming Abstractions in Python, written for the class by the same name at the University of California, Santa Cruz.

The idea of the book, and of the class, consists in teaching students to think about software in terms of objects that have primitive operations. When confronted with a new problem to solve, one should consider what are the objects that are useful for representing the problem, and what operations can be defined on those objects that solve the problem. The operations on objects are often best understood as mathematical operations on the set of objects: considering the properties of the operations leads to cleaner, and more general, solutions.

The book is articulated into five parts:

In the course of the book, we will provide simple implementations of well-known problems. Among other things, we will reimplement the machine-learning framework PyTorch, albeit in a simplified pure-Python setting; we will reimplement the core of Pandas, and we will write Sudoku and Boolean SAT solvers. All these implementations will be concise, minimalistic, and yet powerful, and we hope that they can serve as illustration of how to approach non-trivial software and algorithmic problems.

Book Format

The book chapters consist in Jupyter notebooks. Jupyter notebooks allow literate programming: one can write, in the same place, both the text and mathematics that explains the high-level concepts, and their implementations into code. The notebooks provided here form the book.

The notebooks occasionally contain holes, where you have to fill in code: we leave to you the pleasure and satisfaction of implementing the most fun, and interesting, portions. This is one of the benefits of using Jupyter notebooks: you can play with the material and the code we give you, experiment, and see the effects right away. Instructors can contact the author at luca@ucsc.edu to obtain complete versions of the notebooks, which can be run during a classroom lecture.

What this course is, and is not

This course focuses on the conceptual aspects of programming and software development. The course is not an introduction to particular tools for software development. In particular, the course does not cover topics such as the use of version control, command line, code editors and development environments, Python distributions, and Python package management. These are all worthy topics, of course; however, they are not the focus of the class. At UCSC, where the class is taught, students learn these topics in other classes.

Tools and development environments are important, but they also change and evolve as time passes; the principles covered in this class can be useful across environment and across programming languages.

Acknowledgements

Lindsey Kuper and Peter Alvaro have taught this class at UCSC, and provided invaluable feedback and suggestions. The author is much indebted to Philippe Bossut for inspiration about the approach, and to Massimo Di Pierro for his many suggestions on topics to cover and methods.

Accessing the Content

We provide here the Jupyter Notebooks constituting the chapters, along with the video lectures that accompany them. To access a Jupyter Notebook, you have three choices: you can either follow the link here on GitHub, you can visit the notebooks on Google Colab, or you can download it and run it with Jupyter on your own laptop. Using Colab requires a bit of setup, but has the advantage that you can directly play with the lecture material.