Stack Overflow Users Rejoice as Pattern Matching is Added to Python 3.10

Stephen Brennan • 09 February 2021

INTERNET – Stack Overflow users today rejoiced at the prospect of Python’s upcoming 3.10 release including the controversial new pattern matching feature described in PEP 634.

“Python 3 has been out for a while, and the goldmine of Python 2 to 3 migration questions has started to run dry since January 2020,” said one user, referring to the end of life for the Python 2.x release series. “We were starting to worry that we would run out of major language changes to confuse new developers. But thanks to pattern matching, we should be set for another 5-7 years!”

The question answerers on the popular site, Stack Overflow, were commenting on the upcoming Python 3.10 language feature of pattern matching, which allows syntax such as the following:

match status_code:
    case 200:
    case 404:
        print("HTTP Not Found")
    case _:
        print("Some other shit, sorry!")

Stack Overflow users gushed over its similarity to C’s switch statement. “New users will see the case keyword and instantly feel comfortable based on their knowledge of C,” one SO answerer remarked. “But that’s when we get them! match is about subverting expectations, by assigning to variables when the programmer expects a comparison. We’re going to earn so many Stack Overflow reputation points this way.”

This user’s comments referred to the unexpected behavior of the match statement when used with identifiers:

match status_code:
    case 200:
    case NOT_FOUND:
        print("HTTP Not Found")

In this case, rather than matching status_code against the value of NOT_FOUND (404), Python’s new SO reputation machine match syntax would assign the value of status_code to the variable NOT_FOUND. Another Stack Overflow user explained:

I think the core developers finally looked at the numbers, and saw how few questions Python 3.x was getting on Stack Overflow. Here’s a language that has finally matured, and it really strikes a balance between usability and predictability. When we reached out to the core development team about the dire situation, the developers knew they had to step in and add an unpredictable feature to rectify things.

The last time the Python language conspired so strongly to confuse new users was the controversial “mutable default argument” feature:

>>> def myfunc(x, l=[]):
...     print("myfunc({})".format(x))
...     l.append(x)
...     print(" l={}".format(l))
>>> myfunc(3)
>>> myfunc(5)
 l=[3, 5]

However, some Stack Overflow users were not so rosy about the future of Python 3 questions:

Sure, Python 3.10 is going to trigger a massive influx of questions. But that doesn’t mean we’ll get more reputation points! Most mods are just going to mark all the questions as duplicates, even if they don’t have good answers yet. Pattern matching may be a beautifully booby-trapped new feature, but it’s not going to save us from bad moderation.

Meanwhile, the Perl community rallied in support of the latest developments in the Python language. Said one Perl developer: “Honestly, I’m just glad Python has finally given in to gratuitous new features, and Perl 7 is now the language of reason and moderation. I can’t wait until they realize how many operators they can overload. Maybe Python 2.7 can make a comeback after all?”


Creative Commons License

Stephen Brennan's Blog is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License