8 min read

Python is one of the most used programming languages on the planet. But when something is so established and popular across a number of technical domains the pace of change slows. Moving to Python 3 appears to be a challenge for many development teams and organizations. So, is switching to Python 3 worth the financial investment, the training and the stress?

Mike Driscoll spoke to a number of Python experts about whether developers should move to Python 3 for Python Interviews, a book that features 20 interviews with leading Python programmers and community contributors.

The transition to Python 3 can be done gradually

Brett Cannon (@brettsky), Python core developer and Principal Software Developer at Microsoft:

As someone who helped to make Python 3 come about, I’m not exactly an unbiased person to ask about this. I obviously think people should make the switch to Python 3 immediately, to gain the benefits of what has been added to the language since Python 3.0 first came out.

I hope people realize that the transition to Python 3 can be done gradually, so the switch doesn’t have to be abrupt or especially painful. Instagram switched in nine months, while continuing to develop new features, which shows that it can be done.

Anyone starting out with Python should learn Python 3

Steve Holden (@HoldenWeb), CTO of Global Stress Index and former chairman and director of The PSF:

Only when they need to. There will inevitably be systems written in 2.7 that won’t get migrated. I hope that their operators will collectively form an industry-wide support group, to extend the lifetimes of those systems beyond the 2020 deadline for Python-Dev support. However, anyone starting out with Python should clearly learn Python 3 and that is increasingly the case.

Python 3 resolves a lot of inconsistencies

Glyph Lefkowitz (@glyph), founder of Twisted, a Python network programming framework, awarded The PSF’s Community Service Award in 2017:

I’m in Python 3 in my day job now and I love it. After much blood, sweat and tears, I think it actually is a better programming language than Python 2 was. I think that it resolves a lot of inconsistencies.

Most improvements should mirror quality of life issues and the really interesting stuff going on in Python is all in the ecosystem. I absolutely cannot wait for a PyPy 3.5, because one of the real downsides of using Python 3 at work is that I now have to deal with the fact that all of my code is 20 times slower.

When I do stuff for the Twisted ecosystem, and I run stuff on Twisted’s infrastructure, we use Python 2.7 as a language everywhere, but we use PyPy as the runtime. It is just unbelievably fast! If you’re running services, then they can run with a tenth of the resources.

A PyPy process will take 80 MB of memory, but once you’re running that it will actually take more memory per interpreter, but less memory per object. So if you’re doing any Python stuff at scale, I think PyPy is super interesting.

One of my continued bits of confusion about the Python community is that there’s this thing out there which, for Python 2 anyway, just makes all of your code 20 times faster. This wasn’t really super popular, in fact PyPy download stats still show that it’s not as popular as Python 3, and Python 3 is really experiencing a huge uptick in popularity.

I do think that given that the uptake in popularity has happened, the lack of a viable Python 3 implementation for PyPy is starting to hurt it quite a bit. But it was around and very fast for a long time before Python 3 had even hit 10% of PyPy’s downloads. So I keep wanting to predict that this is the year of PyPy on the desktop, but it just never seems to happen.

Most actively maintained libraries support Python 3

Doug Hellmann (@doughellmann), the man behind Python Module of the Week and a fellow of The PSF:

The long lifetime for Python 2.7 recognizes the reality that rewriting functional software based on backwards-incompatible upstream changes isn’t a high priority for most companies.

I encourage people to use the latest version of Python 3 that is available on their deployment platform for all new projects. I also advise them to carefully reconsider porting their remaining legacy applications now that most actively maintained libraries support Python 3.

Migration from Python 2 to 3 is difficult

Massimo Di Pierro (@mdipierro), Professor at the School of Computing at De Paul University in Chicago and creator of web2py, an open source web application framework written in Python:

Python 3 is a better language than Python 2, but I think that migration from Python 2 to Python 3 is difficult. It cannot be completely automated and often it requires understanding the code. People do not want to touch things that currently work.

For example, the str function in Python 2 converts to a string of bytes, but in Python 3, it converts to Unicode. So this makes it impossible to switch from Python 2 to Python 3, without actually going through the code and understanding what type of input is being passed to the function, and what kind of output is expected.

A naïve conversion may work very well as long as you don’t have any strange characters in your input (like byte sequences that do not map into Unicode). When that happens, you don’t know if the code is doing what it was supposed to do originally or not. Consider banks, for example. They have huge codebases in Python, which have been developed and tested over many years. They are not going to switch easily because it is difficult to justify that cost. Consider this: some banks still use COBOL.

There are tools to help with the transition from Python 2 to Python 3. I’m not really an expert on those tools, so a lot of the problems I see may have a solution that I’m not aware of. But I still found that each time I had to convert code, this process was not as straightforward as I would like.

The divide between the worlds of Python 2 and 3 will exist well beyond 2020

Marc-Andre Lemburg (@malemburg), co-founder of The PSF and CEO of eGenix:

Yes, you should, but you have to consider the amount of work which has to go into a port from Python 2.7 to 3.x. Many companies have huge code bases written for Python 2.x, including my own company eGenix. Commercially, it doesn’t always make sense to port to Python 3.x, so the divide between the two worlds will continue to exist well beyond 2020.

Python 2.7 does have its advantages because it became the LTS version of Python. Corporate users generally like these long-term support versions, since they reduce porting efforts from one version to the next.

I believe that Python will have to come up with an LTS 3.x version as well, to be able to sustain success in the corporate world. Once we settle on such a version, this will also make a more viable case for a Python 2.7 port, since the investment will then be secured for a good number of years.

Python 3 has tons of amazing new features

Barry Warsaw (@pumpichank), member of the Python Foundation team at LinkedIn, former project leader of GNU Mailman:

We all know that we’ve got to get on Python 3, so Python 2’s life is limited. I made it a mission inside of Ubuntu to try to get people to get on Python 3. Similarly, within LinkedIn, I’m really psyched, because all of my projects are on Python 3 now. Python 3 is so much more compelling than Python 2.

You don’t even realize all of the features that you have in Python 3. One of the features that I think is really awesome is the async I/O library. I’m using that in a lot of things and think it is a very compelling new feature, that started with Python 3.4. Even with Python 3.5, with the new async keywords for I/O-based applications, asyncio was just amazing.

There are tons of these features that once you start to use them, you just can’t go back to Python 2. It feels so primitive. I love Python 3 and use it exclusively in all of my personal open source projects. I find that dropping back to Python 2.7 is often a chore, because so many of the cool things you depend on are just missing, although some libraries are available in Python 2 compatible back ports.

I firmly believe that it’s well past the time to fully embrace Python 3. I wouldn’t write a line of new code that doesn’t support it, although there can be business reasons to continue to support existing Python 2 code.

It’s almost never that difficult to convert to Python 3, although there are still a handful of dependencies that don’t support it, often because those dependencies have been abandoned. It does require resources and careful planning though, but any organization that routinely addresses technical debt should have conversion to Python 3 in their plans.

That said, the long life of Python 2.7 has been great. It’s provided two important benefits I think. The first is that it provided a very stable version of Python, almost a long-term support release, so folks didn’t have to even think about changes in Python every 18 months (the typical length of time new versions are in development).

Python 2.7’s long life also allowed the rest of the ecosystem to catch up with Python 3. So the folks who were very motivated to support it could sand down the sharp edges and make it much easier for others to follow. I think we now have very good tools, experience, and expertise in how to switch to Python 3 with the greatest chance of success.

I think we reached the tipping point somewhere around the Python 3.5 release. Regardless of what the numbers say, we’re well past the point where there’s any debate about choosing Python 3, especially for new code. Python 2.7 will end its life in mid-2020 and that’s about right, although not soon enough for me! At some point, it’s just more fun to develop in and on Python 3. That’s where you are seeing the most energy and enthusiasm from Python developers.

Co-editor of the Packt Hub. Interested in politics, tech culture, and how software and business are changing each other.

LEAVE A REPLY

Please enter your comment!
Please enter your name here