|Python 3.10 Is The New Standard|
|Written by Mike James|
|Wednesday, 06 October 2021|
New Python releases come as no surprise as we all know about them during their development and many opt to use them before they are finally released. Python 3.10 has a few welcome improvements, but I'd say none are major - see if you agree.
Recently Guido van Rossum commented that there would probably never be a Python 4. This is partly because of the fuss that moving from 2 to 3 caused and still is causing. Another, and better reason, I think, is because Python is already too mature for an upgrade that would warrant an increment to 4. When you look at the changes and additions introduced in Python 3.10 they are mostly slight - definitely welcome, but hardly meriting a tearing up of the Python manifesto and starting over...
The biggest addition is pattern matching, which I wrote about in Python Adopts Pattern Matching - Kitchen Sink Next. As with all things, after a little time has passed it doesn't seem so threatening. I still have my reservations, but I am glad to have a select or switch-style instruction in Python.
What is not so convincing is the fact that pattern matching is associated with functional programming and strong typing. Python isn't functional in the strict sense and it isn't typed at all, despite the best efforts to make it so. To repeat what I wrote earlier, for example, the tutorial on Python pattern matching gives:
match command.split(): case ["quit"]: print("Goodbye!") quit_game() case ["look"]: current_room.describe() case ["get", obj]: character.get(obj, current_room) case ["go", direction]: current_room = current_room.neighbor(direction) # The rest of your commands go here
That is, command.split divides up a command into words and the case statement matches on the basis of how many words and what the words are. You can see that this is a very compact notation. Look at the ["get",obj] which only matches two-word commands and only if the first is "get" and passes the second on as obj.
When you first see it, this is very attractive. It seems to be Pythonic in the sense that it has a low surprise factor - even a novice will get it. However, things rapidly get much more sophisticated. You can use wildcards, multiple values, guard values and so on. It all reminds me very much of regular expressions - they start out seeming simple and powerful and end up being complex and mystifying. I'm not at all sure that pattern matching really is Pythonic in the true sense - but then Python allows full regular expressions with no training wheels.
I still think this is correct but after living with it I can say that it fits with the language reasonably well, not that I've found that I use it a lot. I only hope that it doesn't confuse beginners.
Beyond this the changes are very small indeed - only two of note:
There are a number of important improvements to the implementation of Python, however. Perhaps most important for using Python as a first language is the improvement to the error-generating mechanism which is now much more precise about what the problem is. This is going to be useful to experienced programmers as well as beginners.
That's about it. There are a number of changes and deprecations in modules but nothing important - just the usual turnover of features.
Now we can sit back and start playing with Python 3.11 where we should start to see some of the payoff from the project to make Python faster.
Acceptance of Pattern Matching PEPs 634, 635, 636, Rejection of PEPs 640 and 642
Guido And Microsoft Want To Make Python x2 Faster
Python Adopts Pattern Matching - Kitchen Sink Next.
Python - Dead Batteries Included?
To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
or email your comment to: firstname.lastname@example.org
|Last Updated ( Wednesday, 06 October 2021 )|