Monday, March 20, 2017

JavaScript vs. Python in 2017

I may be one of the last people you would expect to write an essay criticizing JavaScript, but here we are.

Two of my primary areas of professional interest are JavaScript and “programming in the large.” I gave a presentation back in 2013 at mloc.js where I argued that static typing is an essential feature when picking a language for a large software project. For this reason, among others, I historically limited my use of Python to small projects with no more than a handful of files.

Recently, I needed to build a command-line tool for work that could speak Thrift. I have been enjoying the Nuclide/Flow/Babel/ESLint toolchain a lot recently, so my first instinct was to use JavaScript for this new project, as well. However, it quickly became clear that if I went that route, I would have to spend a lot of time up front on getting the Thrift bindings to work properly. 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.

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 Mypy, and it provides gradual typing, much like Flow does for JavaScript or Hack 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, operating in the style of the Google Closure toolchain.) 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.

In researching how to use Thrift from Python, a Google search turned up some sample Python code that spoke to Thrift using asynchronous abstractions. After gradual typing, async/await 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 improvements to Mypy, fixes to the asyncio API, literal string interpolation like you have in ES6, and more!)

Coming from the era of “modern” JavaScript, 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:

  • In Python 3.6, I can create a new file in my text editor, write Python code that uses async/await and type annotations, switch to my terminal, and run python to execute my code.
  • In JavaScript, I can create a new example.js file in my text editor, write JavaScript code that uses async/await and type annotations, switch to my terminal, run node example.js, see it fail because it does not understand my type annotations, run npm install -g babel-node, run babel-node example.js, see it fail again because I don't have a .babelrc that declares the babel-plugin-transform-flow-strip-types plugin, rummage around on my machine and find a .babelrc I used on another project, copy that .babelrc to my current directory, run babel-node example.js again, watch it fail because it doesn't know where to find babel-plugin-transform-flow-strip-types, go back to the directory from which I took the .babelrc file and now copy its package.json file as well, remove the junk from package.json that example.js doesn't need, run npm install, get impatient, kill npm install, run yarn install, and run babel-node example.js to execute my code. For bonus points, babel-node example.js runs considerably slower than node example.js (with the type annotations stripped) because it re-transpiles example.js every time I run it.
Indeed, the JavaScript ecosystem offers all sorts of tools to speed up this process using daemons and caching, but you or someone on your team has to invest quite a bit of time researching, assembling, and maintaining a JavaScript toolchain for your project before anyone can write a line of “modern” JavaScript. Although you may ultimately achieve a nice edit/refresh workflow, you certainly will not have one out of the box as you would in Python.

“JavaScript is no longer an edit/refresh language.”

Another refreshing difference between JavaScript and Python is the “batteries included” nature of Python. If you look at the standard library that comes with JavaScript, it is fairly minimal. The Node environment does a modest job of augmenting what is provided by the standard library, but the majority of the functionality you need inevitably has to be fetched from npm. Specifically, consider the following functionality that is included in Python's standard library, but must be fetched from npm for a Node project:

As you can see, for many of these features, there are multiple third-party libraries that provide overlapping functionality. (For example, if you were looking for a JSON parser, would you choose parse-json, safe-json-parse, fast-json-parse, jsonparse, or json-parser?) To make matters worse, npm module names are doled out on a first-come, first-serve basis. Much like domain names, this means that great names often go to undeserving projects. (For example, judging from its download count, the npm module named logging makes it one of the least popular logging packages for JavaScript.) This makes the comparison of third-party modules all the more time-consuming since the quality of the name is not a useful signal for the quality of the library.

It might be possible that Python's third-party ecosystem is just as bad as npm's. What is impressive is that I have no idea whether that is the case because it is so rare that I have to look to a third-party Python package to get the functionality that I need. I am aware that data scientists rely heavily on third-party packages like NumPy, but unlike the Node ecosystem, there is one NumPy package that everyone uses rather than a litany of competitors named numpy-fast, numpy-plus, simple-numpy, etc.

“We should stop holding up npm as a testament to the diversity of the JavaScript ecosystem, but instead cite it as a failure of JavaScript's standard library.”

For me, one of the great ironies in all this is that, arguably, the presence of a strong standard library in JavaScript would be the most highly leveraged when compared to other programming languages. Why? Because today, every non-trivial web site requires you to download underscore.js or whatever its authors have chosen to use to compensate for JavaScript's weak core. When you consider the aggregate adverse impact this has on network traffic and page load times, the numbers are frightening.

So...Are You Saying JavaScript is Dead?

No, no I am not. If you are building UI using web technologies (which is a lot of developers), then I still think that JavaScript is your best bet. Modulo the emergence of Web Assembly (which is worth paying attention to), JavaScript is still the only language that runs natively in the browser. There have been many attempts to take an existing programming language and compile it to JavaScript to avoid “having to” write JavaScript. There are cases where the results were good, but they never seemed to be great. Maybe some transpilation toolchain will ultimately succeed in unseating JavaScript as the language to write in for the web, but I suspect we'll still have the majority of web developers writing JavaScript for quite some time.

Additionally, the browser is not the only place where developers are building UI using web technologies. Two other prominent examples are Electron and React Native. Electron is attractive because it lets you write once for Windows, Mac, and Linux while React Native is attractive because it lets you write once for Android and iOS. Both are also empowering because the edit/refresh cycles using those tools is much faster than their native equivalents. From a hiring perspective, it seems like developers who know web technologies (1) are available in greater numbers than native developers, and (2) can support more platforms with smaller teams compared to native developers.

Indeed, I could envision ways in which these platforms could be modified to support Python as the scripting language instead of JavaScript, which could change the calculus. However, one thing that all of the crazy tooling that exists in the JavaScript community has given way to is transpiler toolchains like Babel, which make it easier for ordinary developers (who do not have to be compiler hackers) to experiment with new JavaScript syntax. In particular, this tooling has paved the way for things like JSX, which I contend is one of the key features that makes React such an enjoyable technology for building UI. (Note that you can use React without JSX, but it is tedious.)

To the best of my knowledge, the Python community does not have an equivalent, popular mechanism for experimenting with DSLs within Python. So although it might be straightforward to add Python bindings in these existing environments, I do not think that would be sufficient to get product developers to switch to Python unless changes were also made to the language that made it as easy to express UI code in Python as it is in JavaScript+JSX today.

Key Takeaways

Python 3.6 has built-in support for gradual typing and async/await. Unlike JavaScript, this means that you can write Python code that uses these language features and run that file directly without any additional tooling. Further, its rich standard library means that you have to spend little time fishing around and evaluating third-party libraries to fill in missing gaps. It is very much a “get stuff done” server-side scripting language, requiring far less scaffolding than JavaScript to get a project off the ground. Although Mypy may not be as featureful or performant as Flow or TypeScript is today, the velocity of that project is certainly something that I am going to start paying attention to.

By comparison, I expect that JavaScript will remain strong among product developers, but those who use Node today for server-side code or command-line tools would probably be better off using Python. If the Node community wants to resist this change, then I think they would benefit from (1) expanding the Node API to make it more comprehensive, and (2) reducing the startup time for Node. It would be even better if they could modify their runtime to recognize things like type annotations and JSX natively, though that would require changes to V8 (or Chakra, on Windows), which I expect would be difficult to maintain and/or upstream. Getting TC39 to standardize either of those language features (which would force Google/Microsoft's hand to add native support in their JS runtimes) also seems like a tough sell.

Overall, I am excited to see how things play out in both of these communities. You never know when someone will release a new technology that obsoletes your entire toolchain overnight. For all I know, we might wake up tomorrow and all decide that we should be writing OCaml. Better set your alarm clock.

(This post is also available on Medium.)


  1. Getting inspired by globally successful apps like Facebook, Instagram, Airbnb, Bloomberg, etc. we recommend our clients to develop mobile apps using React Native. If you are looking for a secure, robust and reliable mobile app solution for your business or enterprise, hire React Native developers to avail industry leading React Native development services. React Native is an amazing mobile app development framework from Facebook for cross-platform applications development. It allows you to build mobile apps by using JavaScript. Other than this, you can use a single set of libraries and components for app development for both iOS and Android.

    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai

  2. Thank you for sharing this amazing article.JavaScript originally emerged as a front-end language to provide browsers with dynamic functionality that simply wasn’t possible with just HTML and CSS.Python, on the other hand, is an object-oriented programming language. This is the kind of coding language that allows programmers to build apps and websites using objects that are nothing but virtual building blocks. You need to go with a language that is relatively user-friendly and has a shorter learning curve.

    You can contact any app development company or you can find new app ideas that you could build in order to either improve or learn a new programming language or framework.

  3. This comment has been removed by the author.

  4. "Nice Blog!!
    Norton login is one of the easiest platform that allows you to manage products download Norton antivirus and protect your device from online threats.
    Norton Account
    Norton Setup"

  5. Good Post!!
    AOL Mail serve all the emails in your account, with aol email will get all updates on your mails promptly by creating aol account.
    AOL Account
    AOL Gold Download

  6. When your content is written with perfection, more people will consider your work. People will love what you are speaking about and will listen with calm and patience. Understandability is an important score when considering written content into account. Some people worry about the timely delivery of their affordable paper help. But writers who have written millions of articles in their lives can write great content without worrying about time. They can finish any paperwork within a time framework with ease.


  7. Awesome blog.I find it interesting and is pretty fascinating, By reading your blog i got very useful information.Thanks for sharing this blog.
    Salesforce Consulting Services
    Ecommerce Development Services
    Mobile App Development Services
    Magento Development Services

  8. On this count, Python scores far better than JavaScript. It is designed to be as beginner-friendly as possible and uses simple variables and functions. JavaScript is full of complexities like class definitions. When it comes to ease of learning, Python is the clear winner.

    Find Best app ideas for startups this could be one of the best app ideas for startups who can find opportunity in

  9. Thanks for sharing, this is a fantastic blog post. Really looking forward to read more. Keep writing.

    iOS app development company

  10. You are searching for mobile app development company in Toronto, Canada. AppStudio is a premium mobile app development company in Canada, offering services in Android, React, IOT, Ios, Blockchain & software development on your selected technologies.

  11. Thanks for sharing insight full thoughts I really enjoyed this post.
    Annotation Tool

  12. According to a new report by Expert Market Research, ‘Scrap Metal Shredder Market Size, Share, Price, Trends, Growth, Report and Forecast 2021-2026’, the Scrap Metal Shredder Market size was valued at USD XX million in 2020 and is predicted to register a CAGR of XX% from 2021 to 2026.

    Download a free Sample Report : Scrap Metal Shredder Market Size, Report & Forecast

  13. toptan iç giyim tercih etmenizin sebebi kaliteyi ucuza satın alabilmektir. Ürünler yine orjinaldir ve size sorun yaşatmaz. Yine de bilinen tekstil markalarını tercih etmelisiniz.

    Digitürk başvuru güncel adresine hoşgeldiniz. Hemen başvuru yaparsanız anında kurulum yapmaktayız.

    tutku iç giyim Türkiye'nin önde gelen iç giyim markalarından birisi olmasının yanı sıra en çok satan markalardan birisidir. Ürünleri hem çok kalitelidir hem de pamuk kullanımı daha fazladır.

    nbb sütyen hem kaliteli hem de uygun fiyatlı sütyenler üretmektedir. Sütyene ek olarak sütyen takımı ve jartiyer gibi ürünleri de mevcuttur. Özellikle Avrupa ve Orta Doğu'da çokça tercih edilmektedir.

    yeni inci sütyen kaliteyi ucuz olarak sizlere ulaştırmaktadır. Çok çeşitli sütyen varyantları mevcuttur. iç giyime damga vuran markalardan biridir ve genellikle Avrupa'da ismi sıklıkla duyulur.

    iç giyim ürünlerine her zaman dikkat etmemiz gerekmektedir. Üretimde kullanılan malzemelerin kullanım oranları, kumaşın esnekliği, çekmezlik testi gibi birçok unsuru aynı anda değerlendirerek seçim yapmalıyız.

    iç giyim bayanların erkeklere göre daha dikkatli oldukları bir alandır. Erkeklere göre daha özenli ve daha seçici davranırlar. Biliyorlar ki iç giyimde kullandıkları şeyler kafalarındaki ve ruhlarındaki özellikleri dışa vururlar.

  14. If you want to upgrade Magento version you need following steps.
    Backup your Magento store:
    Creating backups for your Magento 2 site is so urgent and necessary that you can protect all data from the disappearance through Backup Management if there is any change or break on the site. Follow this guide to backup your Magento 2 store.

    You need on Your maintenance mode:
    You should put your store in maintenance mode while upgrading. To enable maintenance mode:
    php bin/magento maintenance:enable
    It will create a new file var/.maintenance.flag. If you cannot disable maintenance mode, you can remove this file [Remember!]

    Upgrade to your Magento version:
    In this case, I will upgrade to Magento version 2. See latest releases at to read more just click here.

  15. If you’re running your business on Microsoft Dynamics AX 2009 or 2012, you are no doubt aware that both software products are approaching the end of their life-cycles. Microsoft is ending Mainstream Support for Dynamics AX 2009, Dynamics AX 2012, and AX 2012 R2 this year and for AX 2012 R3 in 2021. That means no more security updates, hotfixes, warranty claims, design changes, features requests, and self-service support. You can purchase extended support. But be aware that extended support for AX 2009, AX 2012, and AX 2012 R2 ends in 2021. For AX 2012 R3, it will be available until 2023.

    If your business is thinking of upgrading from AX2012 to the latest Dynamics 365version, we recommend a complimentary Dynamics 365 upgrade assessment and cloud migration estimate. With the continuous releases we are seeing from Microsoft, this could be your last upgrade. The complimentary Microsoft Dynamics AX upgrade assessment Nevas Technologies offers to users has helped other businesses tackle obstacles.


  16. This blog was really nice and also very interesting to read it.......
    event organiser in chennai
    Best event planners in chennai

  17. This comment has been removed by the author.

  18. This was a very meaningful post, so informative and encouraging information, Thank you for this post.
    meal kit delivery business

  19. Ah, there is a good discussion about this paragraph in this place on this website. I read all that, so now I am commenting here too... Qualified travelers to Turkey by filling an online form with their personal details can apply visa to Turkey and pay visa cost Turkey online.

  20. I am very ecstatic when I am reading this blog post because it is written in good manner and the writing topic for the blog is excellent. Thanks for sharing valuable information.
    global meal kit delivery services market

  21. Amazing write-up and great share
    Your recent blog post titled How to fix
    Roku Error Code 009 is interesting to read. Your creative style of writing is excellent. I became your big fan after reading. After reading the instructions posted, I could resolve Roku Error Code 009 quickly
    Let me share the post with new Roku users who do not know how to troubleshoot Roku Error Code 009
    Keep posting more blogs and continue the good work

  22. I really enjoyed reading this fantastic blog.. Foreign travelers who wish to travel to Azerbaijan need to apply for e visa to Azerbaijan online that provide the fast and secure visa services.

  23. Thanks for sharing the informative article. I really appreciate your work.
    Hire Magento Developer For Your Ecommerce Business. At Mage Monkeys, We invest in training our developers. Developers at Mage Monkeys are proven with Magento’s high standards and have in-house Magento certifications for back-end and front-end technology. Visit our Website:

  24. Thanks for sharing the informative article. I really appreciate your work.
    Hire Magento Developer For Your Ecommerce Business. At Mage Monkeys, We invest in training our developers. Developers at Mage Monkeys are proven with Magento’s high standards and have in-house Magento certifications for back-end and front-end technology.
    Hire Magento Developers