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 example.py file in my text editor, write Python code that uses async/await and type annotations, switch to my terminal, and run python example.py 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.)

81 comments:

  1. 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.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. "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"

    ReplyDelete
  4. 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.

    ReplyDelete
  5. 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

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

    iOS app development company

    ReplyDelete
  7. This is very informative blog. Thanks for sharing!!
    salesforce consulting services

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

    ReplyDelete
  9. Replies
    1. I know a great company that provides development services on magento - https://dinarys.com/magento

      Delete
  10. 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. https://www.magemonkeys.com/how-to-upgrade-magento-version-from-2-3-2-to-2-3-5/

    ReplyDelete
  11. This comment has been removed by the author.

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

    ReplyDelete
  13. 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

    ReplyDelete
  14. 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: https://www.magemonkeys.com/hire-magento-developer/

    ReplyDelete
  15. I’ve been following your web site for some time now and finally, I decided to write this post in order to thank you for providing us such a fine content!!! Feel free to visit my website; 먹튀검증가이드

    ReplyDelete
  16. Thanks for sharing the info. I located the information very useful. That’s a brilliant story you posted. I will come back to read some more. Feel free to visit my website; 온라인카지노사이트넷

    ReplyDelete
  17. I appreciate your content; please permit me to link this page to one of my content. Jobs That Pay You to Travel With No Experience

    ReplyDelete
  18. Hi, I like your blog. There is a lot of good information on this blog about Web Development Company USA, I loved reading it and I think people will get a lot of support from this blog. Thanks for sharing this informative blog, Please guys keep it up and share with us some unique posts in the future.....

    ReplyDelete
  19. If you are interested to learn how to activate Roku using
    Roku.com/link , let me suggest the blog post titled, How to activate Roku. Read the post a few days back. I could find clear guidelines to activate Roku. Spend your free time reading the post to learn Roku.com/link activation guidelines
    Also please do not forget to share your feedback after reading. The post can help new Roku users who do not know how to activate roku

    ReplyDelete
  20. After going through your blog I realized that there is much vital information that you shared here. I can't finish all at the moment before I will surely come back to read more. Nice job. Call For Proposals 2021 For Developing Countries

    ReplyDelete
  21. Greetings! Very useful advice in this particular post! Thanks for sharing! India business visa , You can apply online for an India business visa via India evisa.

    ReplyDelete
  22. If you are interested to learn Roku.com/link create account guidelines Roku.com/link create account, let me suggest an article titled, How to create Roku account. Read the post a few days back. I’m impressed after reading. Spend your free time reading the article. Also, create your Roku account to proceed with Roku.com/link activation. Also do not forget to share the post on your social media profile
    Let us activate Roku using Roku account and stream the entertaining Roku channels

    ReplyDelete
  23. We take pride in catering custom mobile application development service possibilities to your business and making them stand unique on the App Store & Google Play. We Build Business for You
    Customized mobile applications for multiplying your vision into profits. Let’s discuss your crazy idea with our experts and make it happen for your business.
    https://lilacinfotech.com/what-we-do/app-development

    ReplyDelete
  24. I really love your blog. Thank you...For that, you have to fill the online application form with your personal information as per the requirement, submit it and pay the Indian visa fees accordingly. India visa cost depends on your nationality and your visa type.

    ReplyDelete
  25. Excellent post with the title, How to activate Roku using the portal Roku.com/link activation code I’m Impressed after reading and I have no other words to comment
    I could learn Roku.com/link activation procedure quickly after reading your post. Kindly post similar blogs explaining the guidelines to add and activate the entertaining channels on Roku
    Let me mark the 100-star rating for your blog post
    Keep up the good work
    Awaiting more informative blogs from now on

    ReplyDelete
  26. We do not underestimate students’ skills and talents by providing our services, but we give a guide for high-quality assignments that can help you accomplish major achievements. Get Online grammar check and ensure that your work, essays, research papers, and assignment attain a high level.
    The Progressive Era

    ReplyDelete
  27. Get the best solutions for the web development and get a virtual face that displays you well.
    Best Website Designing Company
    Visit SIfars.com!

    ReplyDelete
  28. Are you planning to hire dedicated iOS app developers for your business? If so, you’re at the right place. AppStudio is the most renowned name for creating iOS apps. We work with the brightest iOS developers to create flawless applications. As a result, we have delivered some of the most amazing iOS solutions to numerous businesses in Canada with dynamic, scalable and feature-packed iOS apps to upscale their businesses.

    ReplyDelete
  29. Nice Blog. Thanks for sharing with us. Such amazing information. 바둑이사이트넷

    ReplyDelete
  30. If you have no time Use best assignment help australia Services for assistance. Writing assignments is difficult, and mostly people find it exhausting. Connect with our assignment helper

    ReplyDelete
  31. Such a very informative article... I appreciate your work... With an Indian e-tourist visa, you can explore all the places in India that have too many things to do. Because India has so many places for vacation, sightseeing, and traveling to India. plan your trip, get a visa and explore India.

    ReplyDelete
  32. Multilingua is a premier education Group that offers the best in-its-class language Education, IELTS training & personalized guidance tostudents who wish to learn and willing to try new and unfamiliarthings. We are also one of the BEST language & IELTS coaching, IELTSTraining Course, English Language Course, German Language Course, French Language Institute, Chinese Language Classes in Delhi, LanguageTranslation services, provide training to a large number of studentsevery year who are looking to work & study Abroad.

    ReplyDelete
  33. Such a very informative article... I appreciate your work.. chinese medine

    ReplyDelete
  34. Religions have sacred histories and tales, which may be kept in sacred scriptures, as well as sacred symbols and holy sites, all of which are intended to give life meaning. I was stumped as to how to write in my leisure time. After reading this article, I became aware of cheap writing services. You will submit quality and top-of-the-line papers for grading if you use their low-cost essay writing services. Your professor will not deny you that extra point that will propel you to the top of the class with the help of dreamscapeartstudio.com At our site understudies find out about what it involves to think of a decent synthesis paper. There are many tips and models that have been created by scholarly authors to keep you 'in-the - know' with respect to what is expected of you when you are composing an exposition structure.

    ReplyDelete
  35. All your hard work is much appreciated. Nobody can stop to admire you. Lots of appreciation.
    토토사이트
    토토
    온라인카지노
    카지노

    ReplyDelete
  36. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post.
    Microsoft Dynamics CRM Support
    Microsoft Dynamics CRM Training
    Microsoft Dynamics CRM Migration
    Microsoft Dynamics Development & Customization
    Microsoft Dynamics CRM Integration

    ReplyDelete
  37. In this period the Chinese document was introduced which was the invention of the teaching of paper support in the classroom the role of the teacher in the classroom was to help in the realization of different activities and spread in many places for the supplementary detail go to the given link dissertationadviser.com this link is usually submitted as the final step to finish a PhD program

    ReplyDelete
  38. Marry James is a writing Expert with 15+ years of experience. Marry is also associated with MyAssignmenthelp.com, where she regularly helps students write their essays/assignments. In addition, Marry also likes to read and has read more than 100 books now.
    Other Service
    Chemistry Exam Help
    employment and industrial law assignment help
    Algebra Exam Help
    Sociology Exam Help
    Computer Science Exam Help
    civil engineering exam help
    finance exam help
    JBC citation
    ISBN citation
    Thermal Engineering Assignment Help

    ReplyDelete
  39. Do you have a website that is not giving the desired results? No matter what your requirements, we will provide customized solutions to you through our website development services. We are Promanage IT Solutions, the most popular and reliable company specializing in website development.

    ReplyDelete
  40. Fascinating comparison between JavaScript and Python! It's intriguing to see how their strengths play out in various development scenarios. For those considering mobile app development, each language's role can vary significantly throughout the project lifecycle. Choosing the right one can truly make or break your app's success!

    ReplyDelete
  41. this is actually awesome
    https://www.onlinedocumentos.com/
    https://www.achetez-permisdeconduire.com/
    https://www.documentoregistrato.com/
    https://www.onlinefhrerschein.com/

    ReplyDelete
  42. omprar carta de condução portuguesacomprar carta de conduçãocompra prontos de conducaocomprar carta condução verdadeiracomprar carta de condução legalcomprar carta de condução bcomo comprar carta conduçãocomprar carta de condução portuguesa

    ReplyDelete