2024-11-14 –, Auditorium
Languages evolve. But how? The infamous "goto" keyword, which for good reason is missing from Python, is a surprisingly "easy" feature to add! Learn how a programming language like Python evolves over time and how new features are added via Python Enhancement Proposals (PEPs). In the process, you'll learn different ways of implementing the goto keyword in Python, and why XKCD number 292 is true.
Jumping to another piece of code is an essential part of how computer instructions are written, but a "raw" goto is generally considered bad practice outside of assembler. Today, we instead have while-loops and methods and all sorts of meaningful abstractions. There are also still valid usecases, even if they're few.
Through the eyes of a fictitious Python Enhancement Proposal (or PEP) for implementing the goto keyword, we will examine the path a PEP takes in real life, the transparent development process of the Python Software Foundation. We will also look at some actual implementations of a python goto keyword, and end up with a brand new goto-enabled version of CPython.
What started me on this adventure was a project to port 1980s text-based game in BASIC to modern Python. Due to the game's old age, it relies heavily on the kind of "spaghetti code" that was typical at the time, but as it turns out, it's not that difficult to add the goto functionality in python either! You might not want to actually do it, of course, but I learnt a lot from attempting it, and hopefully you will too.
Has been tinkering with code in some form for the past 20 years, currently Tech Lead at Kognity. Also a popular science author, with the latest book En Summa av Ögonblick due for release soon. Passionate about education, mathematics, chess, and opinionated style checkers.