Python vs. JavaScript: Is It a Fair Comparison?

Time to read
10 min
Category
Python vs. JavaScript
Table of Contents
  • A quick introduction to Python and JavaScript
    • How Python became one of the biggest programming languages
    • JavaScript’s long way to becoming a general programming language
  • When to use Python vs. JavaScript for mission-critical components
    • Why does Instagram use Python to manage mission-critical servers?
    • Does Instagram use JavaScript?
  • Python vs. JavaScript—which language has more uses?
  • Where does JavaScript win with Python?
  • Is JavaScript better than Python in terms of performance?
  • Machine learning with Python vs. JavaScript
  • The future of Python and JavaScript

When we talk about building a project with Python or JavaScript, we very rarely mean building every software component with one programming language.

That’s just not how modern software development works. If you want to build software that’s up to standards, make it before the deadline, or create an app that will handle millions of users, you’re usually going to end up using several languages, frameworks, tools, and APIs.

So if we want to compare Python vs. JavaScript, we should talk about building mission-critical components of your software with either language.

This is going to be our main theme for this article, and we’ll also talk about:

  • how Instagram became the biggest Python app in the world,
  • what are the most natural applications of Python and JavaScript,
  • how these two languages complement each other.

A quick introduction to Python and JavaScript

Before we get into the nitty-gritty, let’s go over a few basic facts about Python and JavaScript. I won’t bore you with irrelevant details. This is just a rundown of how these languages came to fame, and what’s unique about their current position in the world of programming.

How Python became one of the biggest programming languages

Python first came out in 1991. It was built as a general-purpose programming language, so it can be used to solve any problem that can be quantified and described in code.

The tech market has seen a big surge in Python’s popularity in recent years. It was already popular thanks to web development frameworks like Django, and because it was popular in the academic environment. Then it became the language of choice for machine learning and data processing, which further increased Python’s popularity.

Thanks to the web development framework Django, Python is also quite popular on the web—although not quite as popular as JavaScript. In the 2020 StackOverflow developers survey, JavaScript holds the top position with 67.7% out of 65,000 developers using it. Python is used by 44.1%. In terms of frameworks, JavaScript libraries and frameworks jQuery, React and Angular hold the 3 top spots. Django comes up on the 10th spot.

The cool thing about Python is that it’s used by many scientists and researchers. For people well-versed in the complexities of science, Python is an easy language to learn, even if they aren’t particularly tech-savvy. It’s very useful for fast prototyping, which makes it even more appealing for scientists.

It’s all because Python is one of the simplest languages, but it’s a kind of easy-to-learn, hard-to-master sort of thing. Even if you’re not a programmer, but you want to automate a simple process—like scraping data from a website, or moving data from one program to another—it shouldn’t take you long to get Python to do the work for you.

And if you put the time in and really master Python, you can use it to build a wide variety of software.

JavaScript’s long way to becoming a general programming language

JavaScript first came out in 1995. Web apps weren’t a thing back then, and the goal of JavaScript was to make the web into a real application platform.

JavaScript hasn’t had an easy life. It was hated by a lot of developers due to some of the design choices, as well as poor marketing, and it was limited technologically by low internet speed and low bandwidth. Plus, for a long time there was a problem with cross-browser compatibility, making it hard for developers to build sites that would work on all browsers.

For several years, its popularity was growing at a pretty stable pace. One of the first libraries that removed the issue of cross-browser compatibility was jQuery, released in 2006. It made it easy to add interactivity to websites. The next major framework was AngularJS. It was later replaced by Angular 2+, which is still very popular in enterprise-scale solutions. 

Around 2011/2012 was the first time that JavaScript became supported by all major browsers at the time—Firefox, Chrome, Opera, and Safari. But even now, it’s still not 100% supported. That’s because JavaScript is regularly getting new features, so browser developers have to constantly work on improving JS support.

In 2013, the Facebook engineering team released React, which quickly became popular, and played a big part in cementing JavaScript’s position as the web’s favorite workhorse.

Of course, this is an extremely simplified version of JavaScript’s history; the real version is much longer, and more complex. The main point is that a lot of things had to happen in order to bring JavaScript to where it is now.

At the moment, new versions of JavaScript are becoming more similar in design to a full-fledged general-purpose programming language.

When to use Python vs. JavaScript for mission-critical components

When a mission-critical component or system breaks down for too long, your whole project goes belly-up. This is the part where choosing the right technology really matters.

With low-priority systems, you can browse around, try different options, and optimize costs. When you try to do that with mission-critical systems, you might end up writing a death sentence for your project from the start.

For example, when you’re managing a mature photo- and video-sharing application with over 1 billion users worldwide, the servers that process the incredibly large amounts of content are mission-critical. The app that I’m thinking of is of course Instagram, or “the world’s largest Python site.”

As one of Instagram’s engineers put it, “Instagram Server is entirely Python-powered.” The Instagram server application is a “monolith, one big codebase of several million lines and a few thousand Django endpoints.” Every single photo, video, and like goes through the most popular Python web framework Django, as another Instagram engineer mentioned in a presentation.

Why does Instagram use Python to manage mission-critical servers?

Instagram uses a big chunk of servers at the massive Facebook-owned data centers. Engineers don’t just manage the looks of the app, how your feed works, or the content suggestion algorithms. They literally have to make sure that the CPUs of their servers don’t overheat.

That’s an extremely difficult task. Why did they choose Python as the main language?

The answer can be found on the Instagram developer blog: “We initially chose to use Python because of its reputation for simplicity and practicality, which aligns well with our philosophy of ‘do the simple thing first.’ But simplicity can come with a tradeoff: efficiency.”

Simplicity and practicality. Martin Fowler, a true software development guru with decades of experience, and author of several books, once wrote, “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”

Which means that even when your goal is to make sure that machines don’t overheat from serving billions of users everyday, you don’t achieve that goal by being a better machine whisperer. You do that by writing code that other developers can easily understand, so they can quickly debug it if necessary, or build on top of it without wondering if they’ll break the system.

Python is perfect for this purpose, because of its readability, cleanliness, and ease of understanding.

Does Instagram use JavaScript?

Now we get to the interesting part. Even though Instagram engineers use Python for their whole server, Python isn’t responsible for how the interface looks. It stores and manages all the data, but the interface that you see on your smartphone is built with native programming languages, and a lot of help from JavaScript.

The mobile interfaces are built in Swift (iOS) and Java (Android), but the popular mobile frontend JavaScript framework, React Native, also plays a big part. Instagram engineers chose it because they wanted to have high developer velocity—which means they wanted to be able to add new features to both iOS and Android versions of their app as fast as possible.

React Native is exactly what they needed, because it allows engineers to use the same code to ship features to different systems. They can use JavaScript code to create native interface views on both systems. 

They could’ve used another approach, like building separate interfaces in Swift and Java. But they chose the middle option, and went for React Native. Maintaining interfaces in Swift and Java, with support from React Native, allows Instagram developers to optimize costs and development time, making their life easier. 

Python vs. JavaScript—which language has more uses?

Instagram’s example is a good benchmark for the current web and mobile industry. Many popular apps have a similar structure—Python on the backend and JavaScript on the frontend.

Even PayPal, which is completely different from Instagram, has a similar tech stack. In a very simplified statement, they use Python for managing data and JavaScript for their user interfaces.

The statement is simplified because if you were to get into the specifics of how they use different programming languages and tools, you’d quickly get overwhelmed with the complexity. Plus, they’re not as keen as Instagram on sharing details about their stack with the whole world.

One blog post I was able to find explains that PayPal engineers use Node.js for their middle-tier infrastructure, meaning web servers and their frontend, because it allows them to use only JavaScript to build their sites.

But again, this isn’t mission-critical. The mission-critical parts of PayPal are hidden under all of that, a lot of it coded in Python (and most likely several other languages), and taking care of security, stability, and data management.

JavaScript is not built for mission-critical systems. It started as a programming language for adding interactivity to websites, and even though it has grown into an incredibly useful tool, you could say it’s limited by design.

On the other hand, Python was designed as a general-purpose programming language. It is used far beyond web development. It’s strongly rooted in the academic community. While it can be used to build a great website, with Python you can also build neural networks for developing new drugs or AI technology that hides in the heart of apps like Uber.

So, ultimately, Python has more uses than JavaScript. But there are several areas where JavaScript reigns supreme, so much so that it would be silly to try and use Python for them.

Where does JavaScript win with Python?

JavaScript is a clear winner in the category of mobile development. There are some niche frameworks to do mobile development with Python—like Kivy and PyQT—but pretty much nobody uses them.

It would make more sense for a Python developer to learn JavaScript and use its most popular mobile development framework, React Native, to build an app.

Another area where JavaScript wins is frontend development. It has the best frameworks for building modern interfaces (React, Angular, Vue). With Node.js, developers can use JavaScript to also build the server side of their applications. Thanks to JAMstack (JavaScript + APIs + markup), developers can build super-fast, beautiful web apps within very short deadlines.

For a small/medium web and mobile development team on a budget and with tight deadlines, JavaScript is definitely the best option.

And, as the Instagram and PayPal examples show, when you combine Python with JavaScript, you can build amazing applications that dominate markets and revolutionize life for billions of people.

Is JavaScript better than Python in terms of performance?

JavaScript was built to be fast on the web. When you compare a Node.js web app to a Python app, the Node.js one is almost definitely going to be faster.

As Towards Data Science puts it, “Python is comparatively slower in performance as it processes requests in a single flow, unlike Node.js, where advanced multithreading is possible.”

There are ways to optimize Python’s performance by taking advantage of the fact that it uses the C programming language under the hood. For example, NumPy comes with optimized C code that makes Python code faster. Cython is a compiler, and a superset of the Python language that enables developers to build fast C modules that speed up the execution of Python code.

Generally speaking, JavaScript works well in I/O intensive situations—which means apps like Facebook, where a lot of data comes in and out of the application in real time, and it’s crucial that the user doesn’t have to wait for anything.

Python works well in CPU-intensive situations—like a machine learning model that needs to crunch a huge amount of data to solve a specific problem. It’s also a good language for doing heavy computations using GPUs

Then again, Instagram’s server is more of an I/O intensive situation, but it uses Python. It goes to show that if you know how to optimize Python, you can make it perform quickly.

What about the other side of performance: time-to-market? Both languages can be used to quickly build a simple MVP as long as it’s done by good developers. For complex programs, Python makes for a quicker time-to-market because it’s easy to read and easy to debug. Python fosters smooth collaboration. 

With JavaScript, things can get really complicated, really fast, which can lead to longer development times. For this reason a lot of companies have switched to TypeScript, which some developers would say is even easier to read and maintain than Python.

Machine learning with Python vs. JavaScript

Python is the main language of choice for machine learning developers. It makes a lot of sense. Machine learning is complicated and involves huge amounts of data. Python is a simple and readable language, so it makes life easier for developers by removing complexity, and it has always been the standard for data science.

The most popular ML frameworks—TensorFlow, scikit-learn, PyTorch—are mostly based on Python, and provide dedicated Python APIs which are the most popular way of using them. TensorFlow did release a JS version of the framework in 2018, and it allows developers to build machine learning models that work in the browser or in a Node.js server.

But that’s not enough to win over the ML world. Python is perfectly suited for machine learning, and it’s unlikely to be supplanted by another language in the near future.

The future of Python and JavaScript

Everything we talked about in this article leads to the conclusion that comparing Python and JavaScript isn’t really fair. These languages were designed with different goals in mind, which led to the differences in how they’re currently applied in software development.

And it’s exactly those differences that allow these technologies to perfectly supplement each other in the modern world of programming.

Will that change in the future? At the moment, JavaScript’s position as the most powerful web and mobile application development toolset seems very strong. More and more, it’s being turned into a general-purpose programming language, but it’s unclear if it could be a good substitute for a language like Python.

As for Python, it’s most likely going to continue to dominate the machine learning market, as well as academia, because of Python’s readability and ease of use, as well as its power for manipulating data.

In the end, the choice of your tech stack will always depend on the nature of your project, availability of programmers, and multiple other variables.


Thanks for reading our comparison of Python and JavaScript.

Are you thinking of building, expanding, or refactoring software in the technologies we mentioned? We’d be happy to support you with dedicated developers.

If you’re not sure about your tech stack yet, we can advise you on the best architecture to fit your idea.

Click here to browse our services or click here to contact us directly.

Get your free ebook

Download ebook
Download ebook
Content Writer
Share this post