devxlogo

Python 3.6 May be the Tipping Point

Python 3.6 May be the Tipping Point

Python is a major programming language, eco-system and community. It is influential in numerous domains: scientific computing, Web applications, DevOps, education. It is being used extensively by prominent companies and by hobbyists. But, the Python 2/Python 3 dichotomy caused a lot of frustration for large swaths of the community. I personally, don’t think it hurt Python much. I didn’t see people stop using Python or adopting it less as a first language. There is a significant movement of Pythonistas dipping their toes in Go land, but this is due to Go being more suitable for certain applications compare to both Python 2 and 3 (performance and great built-in concurrency story). For the journeyman Python developer, the difference between Python 2 and Python 3 is not that great. The existence of tools such as 2to3 and libraries such as six is pretty telling. My impression is that little things such as “print” becoming a function can affect people emotionally and cause them to resist change. I believe that Python 3.6 may be a major milestone that can tip the scales toward massive Python 3 adoption. This is important for enterprises because the perceived problem with Python 2/3 can negatively impact starting new projects in Python.

What’s Special About Python 3.6?

I think it’s just the right time. It’s a confluence of several factors:

  1. Python’s 2 support end of life (2020) is in sight
  2. The vast majority of important packages have been ported to Python 3
  3. The asyncio API is stable
  4. Big usability improvement with the new dictionary and literal format strings

For enterprises that depend on Python software the end-of-life is important because there won’t be any more security patches. Large enterprises often need several years to migrate their software. The package situation was always a thorn in the side of Python 3, because the whole Python eco-system is one of its many advantages. If you rely on a package that supports only Python 2, then it doesn’t matter how good Python 3 is, you’re stuck. This is not an issue these days. Check out the Python 3 wall of super powers  or the Python 3 readiness site. The async IO deserves its own article, but it’s looking really good. Finally, I discuss below the new dictionary and the literal format strings.

The New Dictionary

Python 3.6 sports a new dictionary based on PyPy’s work. The new dictionary is about 25% faster (always good). But, the most significant aspect of it is that it is now ordered. Pre-3.6 the native Python dictionary wasn’t ordered. When you iterated its items they were never returned in their insertion order. This gotcha caused a lot of grief. There was OrderedDict from the collections package that provided this functionality, but it was a hassle to use:

  • You had to know it exists.
  • You had to realize you rely on ordering
  • You had to import it first and use the cumbersome OrderedDict class

In the great scheme of things, it’s not a big deal, but it’s exactly the kind of stuff that rubs people the wrong way. This is especially true for a language like Python where productivity is king. Dictionaries are used all the time in Python, so making them easier to use is a major win.

Python < 3.6 (either 2 or 3)---------------------------->>> dict(a=1, b=2, c=3){'c': 3, 'a': 1, 'b': 2}>>> for x in dict(a=1, b=2, c=3).items():...   print(x)...('c', 3)('a', 1)('b', 2)Python 3.6---------->>> dict(a=1, b=2, c=3){'a': 1, 'b': 2, 'c': 3}>>> for x in dict(a=1, b=2, c=3).items():...   print(x)...('a', 1)('b', 2)('c', 3)

Formatted String Literals

String formatting is another common activity in Python. The printf-like percent syntax was deprecated long time ago and the new format() method was all the rage, but it was clunky at times. Consider the following code snippet:

>>> x = 'do'>>> y = 'like'>>> z = 'apples' >>>'Hi, how {x} you {y} them {z}?'.format(x=x, y=y, z=z)'Hi, how do you like them apples?'

Yes, some people used the locals() trick to make it more concise, but it is far less readable and might even be considered a code smell.

>>> 'Hi, how {x} you {y} them {z}?'.format(**locals())'Hi, how do you like them apples?'

The new literal format strings are concise, readable and save a lot of space:

>>> f'Hi, how {x} you {y} them {z}?''Hi, how do you like them apples?'

It’s true that no new functionality was added. You may consider it a syntactic sugar. But, the overall reception is of great excitement. Python People get excited about having a more readable and concise syntax for common operations like string formatting.

Other Awesome Sauce

There were other notable additions to Python 3.6 in the areas of asynchronous IO, security, Windows support that may sway a few other folks that waited just for those features to make it worth their while to switch.

Conclusion

Python 3.6 adds some general usability improvements that may entice the average Python developer to cross from Python 2 to Python 3. It’s bound to happen at some point and I believe that 2017 is that year that Python 3 starts to take over.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist