2024-08-24 –, Breakout Room
Modern Python is better Python. Understanding my older Python code took much more brain power than understanding my newer code. Improvements in readability have been rapid in the last few years as new language features have been harnessed. Before they were incorporated, it often required intense concentration, and the loading of step-by-step details into my memory, to grasp what was happening as information flowed through the code. Using some of the newer Python features has reduced the mental load significantly. The key idea is readability - more of the code has names making it more semantic. It is also more restricted. For example, the inputs and outputs of functions commonly have defined and enforced structures (sometimes using pydantic). All of this makes it easier to work out what code is doing and make changes without getting confused. The main changes are:
1) widespread use of dataclasses (3.6+) as name-rich data structures - especially for function input and output
2) use of type hints (3.5+) as documentation for both input and output
3) use of StrEnum (3.11+) instead of ordinary strings for programmer-defined things
4) using the add_note (3.11+) method on exceptions - adding notes built from f-strings (3.6+) makes it easier to see what is happening when things go wrong.
There has also been a greater emphasis on making the boundaries and interfaces between functions more logical and natural from a human point of view, a change encouraged by the greater use of type hinting and dataclasses. The result is code that is more relaxing to debug, modify, and extend. It is certainly much easier and safer to work on when tired or distracted. Learn how to improve your code using some of the newer features of modern Python.
Anyone
Grant has been an enthusiastic user of Python for many years and has delivered numerous conference talks, meetup presentations, and training sessions on the language. Grant's open source statistics application, SOFA Statistics (over 300,000 downloads to date) is completely written in Python as is the forthcoming replacement SOFA Lite. More recently, Grant has collaborated with Ben Denham to launch the Lean Python (When Of Python) initiative aimed at ensuring Python lives up to its original promise of simplicity and elegance. Grant currently works in the Tech Insights team at 2degrees and was part of the Data Science Team at Qrious where he processed hundreds of billions of records using PySpark and Python.