Python 2 is Stupid

Published: 2016-12-13
Tagged: python software thoughts rants

I don't really think that Python 2 is stupid, having used it for some years. It's the first programming language that I really came to love; heck, it's the foundation of my career.

Python is going through a rough patch at the moment what with the whole py2 vs py3 thing. You can feel something is up. Just visit the Python reddit. There was the over the top Python 3 bashing post by Zed Shaw and the excellent rebuttal by Eevee. When stuff like this happens, I usually just cheer from the stands because I think that the Python community is generally mature and knowledgeable enough to come out of this bloodied but unbowed.

The dam burst when I read Why I'm Making Python 2.8. I have a huge amount of respect for the skill and amount of work required to pull something like this off, but I'm dumbfounded by the approach. This franken-interpreter runs "Python 2 code and C-extensions exactly as-is, while also allowing Python 2 programmers to use the most exciting new language features from Python 3." This sounds like a half-measure, like something made out of duct tape and raccoons, then sold as the final product as often happens in our industry.

If Python 3's features are so exciting, why not just use Python 3? The author touches on this: "And the majority of Python code written does not run under any of the 3.x interpreters. This makes it harder for its users to be productive." Yes, Python 3 is a major version bump and includes breaking changes. Changing a py2 codebase into py3 involves a good deal of work, especially large legacy projects that include unmaintained dependencies. But does this really make it harder for users to be productive?

If it's about moving a codebase over to py3 and getting access to all those goodies, then it's an issue of cost and value. If using new features costs more than the value derived from them then there's really no point in switching over. But you can minimize the cost of the switch by:

Python 2.8 might sound like a good cost minimizer here because it gives you all the new features while only expanding a minimum of resources on changing the interpreter, but I think this is a classic example of going for a short term win and losing the long game. Kinda like grabbing fast-food at the last minute instead of packing a healthy lunch before going to work. Here are some of the long-term costs of going with 2.8:

However, it does have some benefits:

That said, please please please use Python 3. It's extremely pythonic (eg. asyncio is way more explicit than gevent) and hell, switching strings from bytes to text is enough to make it worth the effort. I was well into two years of using Python until I understood how strings work in Python 2 (decode vs encode. This presentation really helped me). Because of how complicated this is, most Python developers that I know simply try random things until something sticks. Python 3 makes this issue really explicit and easy to understand, which is important because most people don't work with bytes - they work with text. Unless you're doing networking or low level stuff, you'll never need to touch bytes and having Python automatically treat strings as unicode text solves 95% of your day to day problems.

Notes

1: Just to get it out there: I'm not a microservice fanatic, I just think it's a useful tool when used consciously.

Comments

There aren't any comments here.

Add new comment