Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Python 3.6 May be the Tipping Point

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 the author believe that 2017 is the year that Python 3 starts to take over.


advertisement

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.



   
Gigi Sayfan is the chief platform architect of VRVIU, a start-up developing cutting-edge hardware + software technology in the virtual reality space. Gigi has been developing software professionally for 21 years in domains as diverse as instant messaging, morphing, chip fabrication process control, embedded multi-media application for game consoles, brain-inspired machine learning, custom browser development, web services for 3D distributed game platform, IoT/sensors and most recently virtual reality. He has written production code every day in many programming languages such as C, C++, C#, Python, Java, Delphi, Javascript and even Cobol and PowerBuilder for operating systems such as Windows (3.11 through 7), Linux, Mac OSX, Lynx (embedded) and Sony Playstation. His technical expertise includes databases, low-level networking, distributed systems, unorthodox user interfaces and general software development life cycle.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date