Python 3.x vs Python 2.7

This was sparked by a disagreement with a friend I’m developing an open source project with. I was in the wrong, I wanted to use Python 2.7 because it was what I learned and was comfortable with (and it was default on my machine). As programmers it is really easy to kill something amazing and fun like a project with a friend with something as stupid as this. It is easy to join a software church without knowing why or having real reason behind it. I hope this will help you understand the differences between the languages and why you should use the newest stable one you can.

What’s the difference?

There are many but the important thing to know is that 3.x is backwards-incompatable.

Sytax differences

Meaning that the code you write for 2.7 will not work in a python 3.x interpreter and vice versa. Here is an article that has a list of the more important syntax changes.

Philosophy differences

There is no real philosophy difference between the development of python 3.x and previous versions. Over time the features in python had grown so fast that there many duplicate ways to do the same thing with subtle, potentially confusing differences. In order to clean all this up a hard fork was needed to remove duplicate features and clean up the language. The language still supports multiple paradigms (OO, stuctured, functional, etc). Yet the goal is that:

“There should be one– and preferably only one –obvious way to do it.” —The Zen of Phython, by TimPeters

Version History

Year Stable Version
2010 2.7
2012 3.3
2014 3.4
2015 3.5
2016 3.6

Will there be a 2.8 release?

In 2014 there was an anouncement that python 2.7 would continue to be supported (bug fixes) until 2020 but that there would be no 2.8 release as users are expected to move to python 3.4+. Source

Why do some continue to use 2.7?

Initially the primary reason ton continue using 2.7 was existing library support. That has since become a mute point because there has been a huge effort put forth by the community to port everything that matters to python 3.x. There is a webpage that tracks the 3.x support of important libraries: 3 Wall of Superpowers

What are the drawbacks to using Python 3.x?

Performance. There are many cases were python 3 is demonstratably slower running similar code. There are many reasons for this yet the reason this is not a real problem is two fold. You won’t be using python if performance is a major concern and second that there are ways to optimize python code that makes it as fast or faster. One of the major sources for this is the change of how types are stored and interacted with. Here is a stackoverflow article about it that shows how to optimize python 3 code to run as fast or faster.

Is there a reason you should use any version besides 3.6 or 2.7?

Debian and all the users of debian on raspberry pi. If you plan on supporting the rasperry pi you will probably want to use 2.7 or 3.4 because those are the ones you can install with apt-get on the current version of debian (the linux distro most commonly used on raspberry pi). You can use 3.6 but you will have to build it from source (stackoverflow). While sure you can do that on your pi, but it will take a long time and your users probably won’t like that. You could also cross compile it, but again your users probably won’t be able to do that easily.

What did I learn?

I am slowly learning to ask the question, “Is this a hill I’m willing to die on?” There is no reason I should kill something awesome like a fun project with a friend and cause a hard fork over something I haven’t spent any real time researching. Also, both python 2 and 3 are verry capable of doing what we need and if I was on the otherside of the argument it wouldn’t matter, the right answer is to not sacrifice something awesome for something stupid. The responsible answer is to use 3.x if you want community support of your project and 2.7 for users who are too religious to do a bit of reading. If this is just for you and your friends it really doesn’t matter unless one of you cares enough to fork the project. If two of you care that much and are different sides, I’m sorry.

Leave a Reply

Your email address will not be published. Required fields are marked *