Python is adding pattern matching syntax - but not everyone is pleased
Making changes to the popular programming language is not easy, says Steering Committee member Pablo Galindo
Python is an extremely versatile programming language that has grown organically over time. That's the reason for its enduring appeal and also a curse on those who would seek to advance it. Equally popular with both school children and cutting-edge AI modellers, any new addition to the language, or tidying of the legacy code base, is bound to raise the hackles somewhere across the language's large and diverse user base.
"No matter what you do, someone will complain at some point," said Pablo Galindo, an infrastructure software engineer at Bloomberg, where 2,000 engineers use Python on a daily basis for tasks that range from simple scripting to web services to server architecture and microservices.
Galindo was recently elected to the five-member Python Steering Council, a body charged with maintaining the quality and stability of the Python language and the CPython interpreter and directing their evolution. He is also a core developer of CPython.
We asked Galindo why he thought Python continues to attract new groups of users 30 years after its introduction, about the challenges of maintaining this momentum, and what we can expect next. The interview is edited for continuity and brevity.
Computing: Python is a favourite first language because of its simple syntax and the fact it doesn't need to be complied, but it's not the quickest. What's the appeal for AI engineers?
Pablo Galindo: Yes, it's ironic because Python is quite slow, while all these applications are relying on speed. If you do heavy mathematical computations in Python, you're going to see that they are almost 100 times slower than with a compiled language. But Python has a huge amount of power to embed compiled libraries. So, for instance, NumPy, Pandas, TensorFlow, Pytorch - they're actually written normally in C or C++ or even Rust, and what Python does is it grabs those libraries and it exposes a way of using them through Python. When you are doing the calculations it's actually C code running, which is very fast. Python is basically a glue language.
The other thing is that [data scientists] want a very fast way to iterate, and that's one of the reasons I think Python is key here. For data exploration you need a very short feedback loop. You don't want to compile for 10 minutes and then maybe run for an hour and now there's an error. You want something that allows you to experiment.
You need a language that doesn't put problems in front of the brain
And you need a language that doesn't put problems in front of the brain, in the sense that the syntax is not fighting you, it's on your side. The syntax is also very easy to learn for people who are scientists and don't have a programming background.
One of the major new developments planned for Python 3.10 (due in October) is structural pattern matching syntax, which is a common feature in many other languages. Why has it proved so controversial for Python?
Pattern matching is a complicated construct that comes from functional languages like Scala and Erlang. There are a lot of a lot of educators and teachers who are saying ‘I don't feel comfortable with this because I need to teach it to people that don't know how to program and this concept can be a bit complicated'. At the same time companies and AI engineers really welcome these changes. There is a big tension between the more corporate usage of the language and other users.
It's not just Python, of course, but with, say, C++ nobody's going to be concerned about adding some extra syntax, because C++ isn't where most people start learning to code.
Can't the teachers just stick to the simple stuff, or is it not as straightforward as that?
Any change in the Python syntax is something that concerns educators because if you have n pieces in your language and then you add one, it's not like you now just have n+1 because of the connections between all of them. It grows as a square, it's exponential growth and it can be dangerous. You not only need to consider the thing that you are adding but also how it interacts with everything else. So maybe the rules the educators have been teaching are no longer true. And yes, many educators and teachers were expressing their concerns very vocally.
As a Steering Council we're trying to make sure that we are in contact with our community, which used to be mainly people working on web servers with Django and whatnot, but is now also data science and machine learning and other groups.
We're trying to adapt ourselves to these new big groups of users. It's a very interesting leadership exercise because you don't have a cohesive community where everybody using Python is a data scientist, that's not true. So, we need to understand the big groups, and then we need to make decisions in the best way not only to facilitate life for this group of users but also to not make life worse, or more complicated, for another one.
So, with pattern matching, we think it's a very good addition. It will simplify a lot of constructs by replacing big chains of conditionals that look really, really ugly, but it's quite difficult to explain thoroughly why we think it's going to be positively good to the whole community.
Guido Van Rossum, the creator of Python, stepped down as ‘benevolent dictator for life' in 2018. How different are things as a democracy?
Ha ha! When we accepted pattern matching people were saying ‘Ah, this is what you get when you have a committee changing the language', but actually the person who proposed pattern matching was Guido. In fact, when Guido was here there were satellite concepts he wasn't used to and he used to delegate a lot of the decisions. Now as the Steering Council, if there is someone who's a prominent expert on a subject then we try to delegate to that person, even if they're outside of the core team.
But it's less pressure on one person. One of the reasons Guido stepped down was because he didn't want to have all this pressure. When he'd say, ‘Okay, this is going ahead' hundreds of people would complain to him, like he didn't have any idea. That's a horrible sensation, right?
Now we are five people with different backgrounds - I'm a physicist not a computer science graduate - so we can bring different viewpoints, and in fact Guido was one of the five when we first set up the Steering Council.
There's a lot of people who would like to have some version of Python running in the browser
So, I think that the biggest change is that now we are five people and we try to be the link between the community and the rest of the core team. You may say that could bring a lack of focus and coherence, but we are making a lot of effort to respect the science of the language itself and not what we individually might want.
So pattern matching is definitely coming in version 3.10. What other changes are you looking at further down the line?
We're looking into ways to make sure that we can scale. This is something that big companies really need. Instagram is a company that is a gigantic Python server, made in Django. And they really need to scale, like they run on thousands of machines with thousands of processors - I'm saying Instagram but it could equally be Bloomberg, for instance, or Google as well.
This is something that people really want, and that also opens up the door for Python in other places like Python mobile or Python in the browser, where now is almost non-existent. We don't intend to substitute for JavaScript, that would be naïve, but there's a lot of people who would like to have some version of Python running in the browser, so they can leverage some of the libraries to do some front-end development like you can in JavaScript, and doing this would help us solve some other issues down the line.