Python 3 Upgrade- Why to do it now in 6 reasons

Ok, It’s About Time to Make the Switch to Python 3python-2-vs-python-3-upgrade

Python 3 was released on December 3, 2008 and seven years later it is still contested in real world applications by its predecessor Python 2. This is odd in the rapidly shifting world of technology. Did we continue to rely on snail mail seven years after e-mail? Were landlines still the norm 7 years after cell phones entered the market? Each was replaced by a better communication technology.

Such is the case with Python 3. It is a better, more pythonic iteration of the programming language. Listed below are six reasons why you should switch to Python 3.

 

2.7 won’t be around forever

 

Because nothing lasts forever, support for Python 2.7 ends the year 2020. That seems far off – so far off that one Stackoverflow user called it the “Windows XP of the programming world”.  To stick with this analogy, the Python 3 would be Windows Vista, but fortunately it is not, & there are some major improvements, and not as much downside as Vista users were initially outraged about. When security updates for 2.7 are no longer pushed out, legacy code will be left vulnerable to attack.

 

If you have a large app and minimal resources, switching is going to take more time, so it is important to start sooner than later. Switching early will give you ample time to handle any broken code and ensure your code is secure moving forward. If you have a large production system implemented as a series of microservices, one route to go might be to switch them over one micro-service at a time. If you have a monolithic application, it might be a good time to start looking at which areas of your application would require changes for Python 3 compatibility.

 

You have or are Building a New Django app

Django is a leader in the Python 3 transition and has supported it for over 2 years since Django 1.5 was released. In addition, Django has written a guide on writing Python 3 source code that is backwards-compatible with Python 2 using compatibility tools such as the six module. Not only does this make your code future proof but it allows you to take advantage of the new features in Python 3 like more sensible string handling.

If you’re building a brand new Django app, now is a great opportunity to begin taking advantage both of some of the updates in Django itself & in Python 3. Though the smaller web framework Flask has some issues with use of Python 3, Django fully supports the latest & greatest of Python.

 

Native async features

As internet connectivity and applications grow, it will become increasingly important ensure that code is responsive and scalable. Python 3.5 works to achieve this using pure python through explicit support for coroutines. Instead of being a new kind of generator, they are implemented as their own type with the async/ await syntax. The goal was to make it easier to conceptualize asynchronous programing and make it as close to synchronous programming as possible.

 

An example (from python.org) is a simple database async transaction like so:

 

The progression of the use of asynchronous tools in the standard lib allows users many of the features of the asyncio library (http://asyncio.org/) without going outside the standard library.

 

Type Hinting

Python creator Guido van Rossum proposed in August of 2014 that future versions of Python include type-checking annotations and with Python 3.5 this is being implemented as type hinting. As a dynamic programming language, introducing type hinting to function arguments gives Python users a bit more control & readability in arguments passed to functions.

 

Forward Development

Finally, no one likes living in the past. While it might seem comfortable, it offers no new opportunities. Python 2.7 might be comfortable, and switching to 3 might seem like a lot of work but it will leave you with outdate unsupported code that doesn’t receive new features or support. Python 3 on the other hand will continue to improve and offer new features that make your life easier.

 

If you’re using Python 2.X, hopefully you’ve been persuaded of the benefits of switching to Python 3. From being able to zip applications to native async features Python 3 currently offers some great advantages and will only continue to get better and offer more.