Blog

Links

Python and JavaScript: mere scripting languages?

posted: February 15, 2020

tl;dr: One of the criticisms of both Python and JavaScript is that they are unsuitable for significant applications...

Python and JavaScript have many more similarities than differences. This is the first in what will likely be a series of posts highlighting these commonalities.

It bothers me when I hear people disparage Python and JavaScript as mere scripting languages. Yes, JavaScript has the word “script” right there in the name (as does TypeScript), with the name suggesting that it is a defeatured version of Java suitable only for short, quick jobs. This impression is completely wrong: JavaScript has much more in common with Python than it does with Java; but it is the burden under which JavaScript labors, because of a marketing decision made when publicly naming the language that Brendan Eich famously developed in ten days.

Both JavaScript and Python arose from humble beginnings, where they were initially used for small script-like tasks: JavaScript within the browser, and Python on the command line. JavaScript started out as a way to add dynamic behavior to web pages, and Python’s initial intent is captured nicely by this quote from its 1992 reference manual, which was reiterated by inventor Guido van Rossum in a 2019 presentation (scroll to slide 9):

I’m not sure there is a clear definition of a “script”, but I will concede that both Python and JavaScript started out as scripting languages. When I think of a script, I envision a short program that is mainly just a series of commands that might otherwise be typed by a user into a console. A script might completely lack functions or data structures other than a few simple variables. I think of Bash as a classic scripting language. Yes, someone has written a webserver in Bash, but that was a lark. For true scripting tasks on a server, I’ll write a Bash script if all I need is a short file which duplicates commands I would otherwise type on the command line. For more complex devops-type scripts, I’ll use Python. NodeJS can certainly be used for scripting tasks, but Python’s much richer standard library gives it the edge most of the time. For scripting tasks within the browser, JavaScript rules.

van Rossum started Python in December 1989, and Eich started JavaScript in May 1995. They were mere scripting languages back then, but that was decades ago. From those humble beginnings both Python and JavaScript have had significant enhancements and adoption. They have grown to become, according to the most recent Stack Overflow developer survey, the two most popular fully-featured programming languages, eclipsing Java, C#, C++, and C, the traditional languages of enterprise software application development.

Today, Python powers the back ends of some of the world’s most popular websites and web applications. It is heavily used in the rapidly growing fields of data science and machine learning. I was an early adopter of Dropbox, which impressed me with how reliably it performed what is actually a difficult task: automatic file synchronization that is integrated into multiple device operating systems. Years later I learned that most of it is written in Python. Dropbox is now a public company with a multi-billion dollar market capitalization. There are plenty of other startups who used Python to grow to become multi-billion dollar companies, as this article entitled 8 World-Class Software Companies That Use Python describes.

JavaScript is still the primary language of the browser, so nearly all sophisticated websites and web applications rely upon JavaScript on the client side. With the development of NodeJS, JavaScript moved onto the server side, where it is also now widely used (see How are 10 Global Companies Using Node.js in Production?). With the development of Electron, JavaScript or its typed variant TypeScript is now used in a variety of desktop applications, including the IDE that I use nearly every day, Microsoft’s Visual Studio Code.

There are still those who believe that serious enterprise applications worked on by large teams of developers need to be written in a statically-typed language that compiles down to machine code. These people tend to believe that static typing is the only way to catch type mismatches before runtime, thereby improving code quality, whereas compiling down to machine code is the only way to make code run fast enough in production. (See Mahmoud Hashemi’s 10 Myths of Enterprise Python.) In reality the type declaration issue is pretty much a solved problem for both languages through the use of optional type checking, and there are plenty of ways to make Python and JavaScript applications performant, especially using today’s scalable cloud infrastructure. These will be the subjects of future blog posts.

Next: The joys of duck typing