Can JavaScript Replace Python

Can JavaScript Replace Python
Can JavaScript Replace Python

Being a long user of both Javascript and Python, essentially since inception I thought it was about time I gave my opinion on this answer. Since this is a multi-facet answer I am going to break it down into different sections to basically give perspective and help you understand if this can be a replacement depending on your needs.

Take for example someone that basically wants to make a web UI for his system, while Python can to some extent with the help of frameworks such as Django and templating accomplish this it’s obviously not the best language for the task. This along with other similar use-cases will be covered in this article trying to shed some light on which language is indeed better for your needs.

Quick Summary

Before I do a deep dive into the specifics, I want to start by giving you a summary if you want to get a quick answer to this. Can Javascript replace Python, I think yes for the most part it can. Below I’m going to analyze some cases where Python may have an edge on it and may be a better solution for you, without trying to discount the power of JavaScript.

Let’s dive right into the summary of things so you can get a clear picture at a high level why I think JavaScript can replace Python as a language.

JavaScriptPython
Client Side ApplicationsYesBad
Server Side ApplicationsYes, via NodeJSGood, Django, Flask etc
FrameworksYesGood
Open LibrariesGood selectionGood selection
Paid LibrariesGood selectionGood selection
SecurityVery goodVery good
CommunityVery goodVery good
SupportExcellentExcellent
SpeedGoodExcellent
Learning CurveEasyEasy

As you can see above both languages are excellent, really this is a battle of giants here. I think JavaScript clearly can replace and superseed Python as a language. Lets dive more into the specifics now and take a deeper look so you can isolate what you are looking for more specifically and find your answers.

Client-Side Support

Can JavaScript Replace Python - Client Side
Can JavaScript Replace Python – Client Side

When it comes to client side applications I mean web and application front-ends. So that is code that runs visually for a user to see. Javascript has a lot of options here but on the other hand Python has very few native ones. If we take a look here for the frameworks that are for client side and ui stuff for Python you’d see the following:

  • PyQT
  • Kivy
  • Tkinter
  • Django (to some extent via templating engine)

As you can see from the list above there’s something clearly missing and this is basically stuff for the Web and for mobile applications. Clearly Python was not designed for this. On the other hand Javascript can easily replace Python for client side applications as it has a lot of very good web and mobile frameworks. A list of some are the following:

  • Angular / Ionic JS
  • Vue JS
  • React Native/JS
  • Express JS

The list goes on forever I can probably give you much more examples here but I’ll keep it short I think you get the point that essentially Javascript is much better at getting this job done than Python so it can easily replace it.

Server-Side Support

Can JavaScript Replace Python - Server Side
Can JavaScript Replace Python – Server Side

In contrast with client side applications, server side applications are favoring Python. Sure Javascript can replace Python here but the battle is much more tough. For example Python has a plethora of good server side frameworks that are actually very good at getting the job done fast and easy. Here’s some I’ve used in the past that I can vouch for:

  • Flask
  • Django (supports multiple backends)
  • Pyramid
  • FastAPI
  • Bottle
  • Eve

The list can go on forever here as there’s a new one every other day. If you take a look now in JavaScript we have basically the inverse situation that we had with the web UI.

  • Express.js
  • Fastify
  • Next.js

Even though there’s more and this is an area that’s definitely growing for Javascript the list above is definitely limited to some extent. I may have missed some but my point here is that JavaScript can replace Python for server side applications but Python definitely has the edge.

Speed

The speed of execution is one of those things that are very hard to quantify when it comes to a programming language. Let me just say that in modern scalable systems such as the cloud things matter and they matter a lot. A small hiccup and you can delay processing an important function.

While both have a good history of running fast, I think both are limited by the fact that they are really limited to one processor. With Python you can use multiprocessing to get around that but the language itself does not use more than one core to execute things. Similarly Javascript in NodeJS and the web code is limited to using one core. This leaves all the work on the programmer if he wants to do concurrency. So I’d say JavaScript can replace Python for speed because they are both kind of neutral.

To better help you understand I did a benchmark in both languages Python and NodeJS to compare them in the following factors:

  • Loops
  • Threads
  • I/O
  • Scheduling

JavaScript Replace Python - Speed Chart
JavaScript Replace Python – Speed Chart

The values I used above in the X-axis is the speed in milliseconds so the higher the value the slower it was. In my opinion these values indicate that basically the languages are close to a tie in most cases, making me think that JavaScript is a good replacement for Python when it comes to speed.

Frameworks

As we mentioned earlier in the client and server side sections Python has better frameworks for server side without discounting that Javascript has a few decent ones that can accomplish just as good of a job. However on the client-side Javascript is a clear winner having much better frameworks. From the above I think it’s easy to say that Javascript can easily be used instead of Python if you are taking into account frameworks.

Open Source Libraries

Both Python and Javascript have good open source Libraries. The frameworks we mentioned above are great examples but those are not limited to that. Both languages have great libraries provided by the community to help you accomplish a lot of micro-tasks. In my experience there’s no clear winner here, when I try to perform tasks I have been able to find what I needed in both Python and JavaScript. Since both have a feature rich library availability I’d say that JavaScript can replace Python when it comes to open source Libraries.

Can JavaScript Replace Python - Open Source Libraries
Can JavaScript Replace Python – Open Source Libraries

Keep in mind that there’s a few niche exceptions to the rule above such as data science applications. In this field Python is particularly better with NodeJS and Javascript in general having no good answer to it. If you are into data science I recommend you go specifically with Python so in that case Javascript is still not a replacement for Python. This may well change overtime as things change but this is the situation as is right now. As a side note I have two good articles on data science particularly Natural Language Processing with Python that you may want to check out here:

Paid Libraries

JS Replace Python - Paid Libraries
JS Replace Python – Paid Libraries

My experience with paid libraries is rather limited I have to admit however I do have some exposure in both ends. I think this is again one of those ties where both languages have a good support by third party commercial libraries that require licensing. If you are looking for a specific application here you need to look specifically for your use case and what’s out there. Since the range is pretty wide on what’s available it will depend. For example I wanted a good and fast PDF mining library since I had difficulties doing so with what was available for Javascript and I ended up paying for one in the past. Since then new libraries came out and the problem has been resolved with open source but it’s a good example of why it’s hard to quantify and say if Javascript is a good replacement for Python here. The judgement is on you on that one sorry.

Security

Security Bug JS Replacement Python
Security Bug JS Replacement Python

A fundamental aspect of every language is security. Coming from a security background myself I’ve known the intricacies of both engine implementations. More particular CPython and V8 engine. Since security is an ever evolving thing we can only go by the reported vulnerabilities and well of a job the teams do to fix them.

In the case of both JavaScript and Python I can confidently say that they are both fairly good at resolving and identifying the security issues. They both have open reporting programs that basically give some recognition to the person finding the security leak. Since they are equal here I think JavaScript can replace Python as a secure alternative. The one thing to keep in mind is that you need to stay current with the news at the time.

A small security vulnerability is unlikely to happen in the core engine but it does often surface. Immediately take remediations on it if it happens. I want to stress out here that security isn’t only about the core engine of the language but also of the frameworks, libraries extensions or even paid third party extensions to it. It is your responsibility to do research when you use any of the above and ensure it complies with the language, this isn’t something the framework will solve for you.

Learning Curve

Learning Curve JS replace Python
Learning Curve JS replace Python

Both JavaScript and Python have relatively short learning curves. Since you may be coming from a Python background and you are looking if the same applies for JavaScript to replace Python, I’d say yes. Javascript also has a short learning curve and it’s very easy to understand especially if you are already knowing how to use a loose typed language like Python.

JavaScript is a good replacement for Python when it comes to understanding its basic structures. While the syntax is closer to a language like C in the loops and has a lot of functional related functionality the way you code JS may differ from Python but that doesn’t mean it cannot replace it. I personally like the syntax of both favoring slightly JavaScript since I come from a C background. So don’t be afraid to make the switch if you are considering learning a new language like Javascript.

Popularity

Popularity is one of those factors that can affect your decision in many ways if you are considering a switch from Python to JavaScript as a replacement. The reason for this is that the more popular a language is there’s a set of cascading effects that may influence a lot of other things. I’m going to list some below just so you can see the implications of it:

  • More users using the language thus more bugs being found and reported.
  • More money going into the programming language and grants for funding it, thus improving in all aspects such as:
    • Speed
    • Support
    • Bug fixing
    • Security
  • Bigger community thus you will be finding more answers effectively
  • A wider set of new libraries being introduced as more individuals will be participating and using the language
  • Increased visibility to other projects and more integrations with third party applications.
  • Companies will be more inclined to offer APIs and SDKs for that particular language.

As you can see from the list above the list is pretty big and it’s easy to understand that the impact of popularity is probably one of the biggest determining factors not only for the future of the language but the success of it too. In order for me to better understand this I will pull some graph from Google trends to help me give you a picture of how the popularity of each has gone over the past 2 years.

trend - javascript vs python
trend – javascript vs python

Are you seeing what I’m seeing in the chart? Yes the giants go hand in hand at almost every month. Even when there was a downfall both followed through it. If you notice closer however you will see that JavaScript popularity tends to go up by 10-15% over Python’s popularity but then they end up evening out but JavaScript always has this slight advantage. It’s rare to see this close of a battle but clearly Javascript is a replacement for Python world coders!

Now let’s look a slightly different of a study and this is how it trends in different countries around the world. This will give us perspective in the English language speaking countries as this is where most documentation and support forums are on.

country trend - javascript replace python
country trend – javascript replace python

This is where we see a big difference in things. More specifically Javascript is much more popular in the western world particularly in the US where a lot of the cloud technologies and mobility is born. In contrast in the eastern part of the world you can clearly see that Python is more popular. My only explanation on this is that the Eastern world does not have as much of mobility applications as the West does.

I am not trying to discount the East on that aspect but this is based on where most apps live in. As you know and we discussed earlier Javascript is king when it comes to web and mobility UI frameworks with the dominants being React JS/Native and Angular/Ionic. This would explain the massive difference we are seeing with the introduction of the apple and google playstores.

Hopefully this gives you some perspective and allows you to decide which one to go with as popularity is definitely a deciding factor for the faith of the language and I conclusively can say Javascript is ahead of Python and may soon be replacing it.

Support

JS Community and Support vs Python
JS Community and Support vs Python

Closing I want to talk a bit about support and how that fares when coming from a Python world into JavaScript. When I opened up this article I said this is the battle of the giants. Think no further away the same holds true when it comes to the community and the support of both of them.

You can easily transition to JavaScript from Python when you are considering a community and the support you will find. There’s ample amount of resources for both languages particularly JavaScript. I think it’s an ever growing thing and I do not see this getting any smaller anytime soon. Keep in mind that while Python’s community and support is very much focused on specific niches, one of which I mentioned earlier like data science. JavaScript is very much focused on web ui and general mobility stuff.

If you happen to be in that niche not only would I say that JavaScript support will surpass Python but I would even say it may give you the answer in a silver platter many times. If you happen to fall in the data science field like I mentioned earlier then you will really need to re-consider replacing Python with JavaScript as you will find yourself struggling with the lack of online resources and support.

Related

References

Leave a Comment

Your email address will not be published. Required fields are marked *