I just had the pleasure of giving a talk at this year’s PyCon UK in Cardiff on the issue of syntax errors and error messages in Python. The talk is based on my research on syntax errors, student misconceptions, and error messages in Python, where I try to give a brief overview of my work. … Continue reading PyCon UK 2019
Category: Python
Dennis Komm and I have been invited to give a workshop in the education track at this year’s PyCon SK in Bratislava, Slovakia. Unfortunately, our overall workload left little room to attend many of the other sessions (not speaking Slovakian was certainly a further impediment), but the little we saw was interesting and impressive enough. … Continue reading PyCon SK 2019
A copy of this article is available on GitHub: it might turn out to be better readable with GitHub’s formatting. Introduction As part of a recent project, I needed to analyse the abstract syntax tree (AST) of Python programs. To illustrate the task, let us consider a piece of a code that is supposed to … Continue reading On the Syntax of Pattern Matching in Python
Introduction and Motivation If you want to analyse, or even optimise Python code, you probably want to do that on the basis of the Abstract Syntax Tree (AST). The AST is, as the name suggests, an abstract representation of the code in the form of a tree structure (see also my article on Implementing Code … Continue reading Implementing Pattern Matching in Python
The Idea of Tail Call Optimisation There is a famous family of numerical sequences, which can be built according to a very simple pattern. You start with an arbitrary positive integer as your first number in the sequence. Whenever your number is even, you divide it by two. Otherwise, you multiply it be three, and … Continue reading Why Optimising Python is Hard (3): Tail Call Optimisation
You can easily nest functions in Python. That is, you define a function inside another function. This leads to a significant challenge, though: how can a nested function access variables of the surrounding function, when the surrounding function might already have died? Somehow, a function needs to capture all necessary variables it needs to properly … Continue reading Closures in Python
We are on a quest to optimise Python programs. More specifically, we want to replace instances where builtin functions are called with known arguments, such as len(‘abc’), by the respective result (which would be 3 in this case). In order to succeed, we must make sure that the name len really refers to the built-in … Continue reading Why Optimising Python is Hard (2): Messing with Namespaces
Among proposed optimisations for Python, we find, for instance, the notion of replacing a call like len(‘abc’) by its value (3 in this case). On the one hand, implementing such optimisations makes sense only if the respective instances are executed very often in a program. Otherwise, the gain is just way too small to bother. … Continue reading Why Optimising Python is Hard (1)
Have you ever wondered how a compiler might actually optimise your code to make it run faster? Or would like to know what an Abstract Syntax Tree (AST) is, and what it might be used for? In this article I am going to give an overview of how Python code is transformed into tree form … Continue reading Implementing Code Transformations in Python