(One of my summaries of a talk at the 2021 10th Dutch PyGrunn one-day python conference).
Note: Łukasz Langa is the author of the wonderful black code formatter.
Note 2: I made a summary of a different pattern matching talk last month.
Łukasz started making a small game to learn about python 3.10’s new pattern matching functionality. Actually programming something that you want to finish helps you to really delve into new functionality. You won’t cut corners.
One of the things he automated in the past was a system to manage his notes, for instance to export notes marked “public” to his weblog. His notes are all in git. Lots of notes. An advice unrelated to the rest of the talk:
Keep notes.
Own your data.
Automate with python.
He showed the source code for his simple game. One of the methods was 15 lines
of an if/elif with some more nested if/else statements. if
isinstance(...)
and so. He then showed the same code with the new pattern
matching of python 3.10. Matching on types, matching on attribute values.
match
and case
may seem very weird now in the way they are
implemented. But he thinks they can become pretty useful. You won’t use them a
lot, normally. But in some cases it’ll make your code more neat and clear. It
seems useful.
My name is Reinout van Rees and I program in Python, I live in the Netherlands, I cycle recumbent bikes and I have a model railway.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):