paint-brush
JavaScript vs. Python in 2017by@mbolin
108,551 reads
108,551 reads

JavaScript vs. Python in 2017

by Michael Bolin8mMarch 20th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<em>I may be one of the last people you would expect to write an essay criticizing JavaScript, but here we are.</em><br>&nbsp;<br>Two of my primary areas of professional interest are <a href="https://www.youtube.com/watch?v=M3uWx-fhjUc" target="_blank">JavaScript and “programming in the large.”</a> I gave a <a href="https://www.youtube.com/watch?v=PCL3dXQZ_Wk" target="_blank">presentation back in 2013 at mloc.js</a> where I argued that static typing is an essential feature when picking a language for a large software project. For this reason, <a href="http://blog.bolinfest.com/2017/03/python-airing-of-grievances.html" target="_blank">among others</a>, I historically limited my use of Python to small projects with no more than a handful of files.<br>&nbsp;<br>Recently, I needed to build a command-line tool for work that could speak Thrift. I have been enjoying the <a href="https://nuclide.io/" target="_blank">Nuclide</a>/<a href="https://flowtype.org/" target="_blank">Flow</a>/<a href="https://babeljs.io/" target="_blank">Babel</a>/<a href="http://eslint.org/" target="_blank">ESLint</a> toolchain a lot recently, so my first instinct was to use <a href="https://hackernoon.com/tagged/javascript" target="_blank">JavaScript</a> for this new project, as well. However, it quickly became clear that if I went that route, <a href="https://github.com/apache/thrift/pull/1175" target="_blank">I would have to spend a lot of time up front on getting the Thrift bindings to work properly</a>. I couldn’t convince myself that my personal preference for JavaScript would justify such an investment, so I decided to take a look at Python.<br>&nbsp;<br>I was vaguely aware that there was an effort to add support for static typing in Python, so I Googled to find out what the state of the art was. It turns out that it is a tool named <a href="http://mypy.readthedocs.io/en/latest/" target="_blank">Mypy</a>, and it provides <a href="https://en.wikipedia.org/wiki/Gradual_typing" target="_blank">gradual typing</a>, much like <a href="https://flowtype.org/" target="_blank">Flow</a> does for JavaScript or <a href="http://hacklang.org/" target="_blank">Hack</a> does for PHP. Fortunately, Mypy is more like Hack+HHVM than it is like Flow in that a Python 3 runtime accepts the type annotations natively whereas Flow type annotations must be stripped by a separate tool before passing the code to a JavaScript runtime. (To use Mypy in Python 2, you have to put your type annotations in comments, <a href="https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler" target="_blank">operating in the style of the Google Closure toolchain</a>.) Although Mypy does not appear to be as mature as Flow (support for incremental type checking is still in the works, for example), simply being able to succinctly document type information was enough to renew my interest in Python.<br>&nbsp;<br>In researching how to use Thrift from Python, a <a href="https://hackernoon.com/tagged/google" target="_blank">Google</a> search turned up some sample <a href="https://github.com/facebook/fbthrift/tree/master/thrift/tutorial/py.asyncio" target="_blank">Python code that spoke to Thrift using asynchronous abstractions</a>. After gradual typing, <code class="markup--code markup--p-code">async</code>/<code class="markup--code markup--p-code">await</code> is the other feature in JavaScript that I cannot live without, so this code sample caught my attention! As we recently added support for building projects in Python 3.6 at work, it was trivial for me to get up and running with the latest and greatest features in Python. (Incidentally, I also learned that you really want Python 3.6, not 3.5, as 3.6 has some important <a href="http://mypy.readthedocs.io/en/latest/python36.html" target="_blank">improvements to Mypy</a>, <a href="https://bugs.python.org/issue28613" target="_blank">fixes to the </a><code class="markup--code markup--p-code"><a href="https://bugs.python.org/issue28613" target="_blank">asyncio</a></code><a href="https://bugs.python.org/issue28613" target="_blank"> API</a>, <a href="https://www.python.org/dev/peps/pep-0498/" target="_blank">literal string interpolation like you have in ES6</a>, <a href="https://docs.python.org/3/whatsnew/3.6.html" target="_blank">and more</a>!)<br>&nbsp;<br>Coming from <a href="https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f" target="_blank">the era of “modern” JavaScript</a>, one thing that was particularly refreshing was rediscovering how Python is an edit/refresh language out of the box whereas JavaScript used to be that way, but is no more. Let me explain what I mean by that:

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - JavaScript vs. Python in 2017
Michael Bolin HackerNoon profile picture
Michael Bolin

Michael Bolin

@mbolin

L O A D I N G
. . . comments & more!

About Author

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite