loading...
Cover image for Why I prefer JavaScript over Python

Why I prefer JavaScript over Python

hanna profile image Hanna ・2 min read

Over the years I've been using Python less and less. This has become more and more apparent as my GitHub and other websites I store code on have little to no Python on them anymore.

Performance

Don't get me wrong Python is a good language for small scripts and things but once it gets to larger projects, such as backends that will most likely be under heavy load, the interpreter starts becoming quite sluggish. An example of these kind of speed differences can be seen here.

Syntax

Another reason I personally tend to not use Python is I'm someone who started with languages like C++ at a early age, I'm more akin to languages with C-like syntax rather than ones with syntax like Python's as it feels weird, and finicky to me compared to say something like JavaScript which still uses brackets, semicolons, and other small syntactic details. As an example, something like the following:

function hello() {
  console.log("hello world!");
}

hello();
Enter fullscreen mode Exit fullscreen mode

personally feels a lot more grammatically correct in a way than something compared to python, with say how it defines functions:

def hello():
  print("hello world!")

hello()
Enter fullscreen mode Exit fullscreen mode

Package Management

Now this one is going to be a bit of a "hot take". Node's package management is quite literally hell compared to Python's for a few reasons. One of these reasons is that instead of a central cache each project or repository uses, each project has their own instead of just reusing existing cached ones. This results in things taking up more space than need be, and overall the inclusion of libraries in libraries and those depending on libraries that are per-project is a mess.

Python's package management is a bit nicer as you don't exactly have a module folder per-project and rather you install the module or library "globally" for any project to use. This method is much cleaner and saves space and time as I don't need to redownload every library or package I need, if another project has already needed it in the past.

Last Words

Every language has their own pitfalls, however Python's when it comes to large scale projects are a bit too much for me, mainly regarding performance. Though In the end you should probably use another language (preferably one that's compiled) for a backend, especially one that will be under heavy load, to get the most performance and stability out of it.

Discussion

pic
Editor guide
Collapse
akshay090 profile image
Akshay090

I feel that the libraries around web dev and the ecosystem is much stronger for js than python.

Collapse
onlinecoursesgalore profile image
Collapse
hanna profile image
Hanna Author

I can't confirm nor deny this as I haven't used Python in such a while that I'm unsure how their ecosystem compares to node at this point.

Collapse
kilo59 profile image
Gabriel

I don't think its quite fair to compare modern day node.js to an old WSGI based web framework like Flask.

Modern Python web frameworks are ASGI based.
My personal favorite is FastAPI but there are many more

Thread Thread
arcbjorn profile image
Arc

Hi! I would love to get into python web. :)

Could you share your experience using FastAPI? And why you like it?

Is it correct that FastAPI is based on Starlette, which is based on Uvicorn? So why not use Uvicorn for small projects and FastAPI for something bigger?

How mature is FastAPI in your opinion? Comparing to Django for example. Reliable in production?

Collapse
tombohub profile image
tombohub

Except ORM. Why is that?

Collapse
akshay090 profile image
Akshay090

Libs. like prisma, typeorm etc. are really great

Collapse
javaarchive profile image
Raymond

One thing I find is that I can read javascript code better than python for some reason. I did python flask for 2 years and when I started using nodejs express with some libraries, I was like wow I've been missing out on a lot

Collapse
jingxue profile image
Jing Xue

IMO, npm actually does a much cleaner job than pip, by managing dependencies at the project level, thus avoiding Dependency Hell. Indeed python developers these days turn to tools like virtualenv or pipenv for per-project dependency management.

Collapse
thefern profile image
Fernando B πŸš€

pnpm does an even better job than pip and npm. You use pnpm like npm but it will download only once to pnpm local store and reuse module in projects. Saving space and downloading while giving same interface like npm.

Collapse
hanna profile image
Hanna Author

If only it was the default package manager, maybe in the future.

Collapse
bionboy profile image
Luke Floden

Also Anaconda

Collapse
andrewbaisden profile image
Andrew Baisden

I like them both as they have their own advantages over each other. You can never have too many programming languages and I like being able to switch between a Node/Express back end and a Python/Flask back end. I am still new to Python as my main language has been Javascript for years.

Collapse
mzaini30 profile image
Zen

You can using PNPM for make all node_modules symlink to root. It's reduce disk memory and internet for downloading already packages.

Collapse
hanna profile image
Hanna Author

It's nice, but sucks it isn't the native package manager.

Collapse
rohitjethoe profile image
Rohit Jethoe

or just use npm i -g

Collapse
hanna profile image
Hanna Author

Doesn't work on a per project basis

Collapse
bloodgain profile image
Cliff

The criticism of Python's performance isn't totally off-base here, but it's incomplete. Yes, the CPython interpreter is not the fastest. But among interpreted languages, it's not bad.

A friend of mine's favorite work-time hobby is proving that when someone says "Python is too slow", it's because they're not a good programmer, not because of Python. It's usually down to mistakes -- that are often made in other languages, too -- like using loops and especially nested loops unnecessarily, bad handling of data types (string manipulation is usually the worst offender), blocking on I/O instead of doing it asynchronously, not leveraging the language features, etc. Note that this same friend wrote and maintains a Python-based application that manages high-def, high-speed camera data on a network link that has to be handled in a bitstream (i.e. OSI Level 1, no packetizing) because it saturates a 10 Gbps link in raw throughput. Yes, some of that got optimized into Cython, but by starting with Python, he was able to have a pretty performant version written in a month full of weekends and continue optimizing and extending it from there.

Python cares more about productivity than performance, but it gives you the tools to write for performance, too. It just doesn't optimize prematurely.

Collapse
magesh236 profile image
Mageshwaran

They both are good, each have its own ecosystem.
When you are building a project you also need to consider these things time to build, knowledge about the language, what kind of project(backend or frontend), etc.
Some times you may use both of them in the same project.

Collapse
magesh236 profile image
Mageshwaran

When you learned the first programming language, it will be easy to learn other programming language.

Collapse
ericgeek profile image
EricGeek

As someone that's been programming in C since before the Berlin wall fell, I really have to agree with the syntax, it just feels more comfortable. This same reason is probably why I'm on the side of optional semicolon usage in JavaScript.

Collapse
soonhongooi profile image
soonhongooi

actually tried out python Flask for our internal project to create restful services for the lul. quickly regret it.... If you're one who's fluent in OO language like c#, python can quickly become a nightmare.

Collapse
kilo59 profile image
Gabriel

Flask is pretty dated, use something like FastAPI

Collapse
swastikgowdal profile image
Swastik Gowda

MY first programming language was also c and c++ , so because of that i got comfortable with its syntax and rules and after sometime i started learning python which was easy though but i didn't feel like i was at home , so then i started leaning js and got married to it

Collapse
tehomcd profile image
TehomCD

If performance and C-like syntax are things you look for, you might really like Go. I like both python and javascript, but have been using Go more and more often on the backend due to its speed and simplicity.

Collapse
kodebae profile image
KodeBae

I see. So it's more like a preference. I started learning Python a few days ago and I must say that I also find it slightly off somehow. Because I'm not 100% accustomed to it yet. But I do enjoy the syntax because it's very easy to read. I'm hoping I get better with it along the way as time goes on. :)

Collapse
hanna profile image
Hanna Author

I agree! I'm learning Elixir and the syntax and things throws me off, just gotta get used to it!

Collapse
kodebae profile image
KodeBae

I'm using it to solve hard algorithm problems and they are so confusing.

Collapse
onlinecoursesgalore profile image
Online Courses Galore

Since it is the scripting language of the browser I would suggest that people should learn JS first if they are considering programming..

Collapse
web_dev_ayush profile image
Ayush Kumar Singh

I have learned both Javascript and python and I think personally on the web you can do a lot of things easily with Javascript in comparison to python. Most of which is compatibility with different things.

Collapse
tombohub profile image
tombohub

Can you do ORM easier?

Collapse
ousstack profile image
Oussama

but when it's come to machine learning and big data and AI, javascript suck in that particular area

Collapse
hanna profile image
Hanna Author

That is a fair point, lol.

Collapse
shadowtime2000 profile image
shadowtime2000

I too don't like Python because of it's syntax because I started programming with Java and it feels weird writing it with semicolons.

Collapse
mlsci profile image
MLSci

With or without?

Collapse
agiboire profile image
Adrien

*You

Collapse
shadowtime2000 profile image
shadowtime2000

Missed that mistake, it was without :D

Collapse
dominikbraun profile image
Dominik Braun

If you're a capable developer you will acknowledge that both have their strengths and weaknesses. It is fine to prefer one over the other, but your best bet is to put both of them into your toolbox.

Collapse
ryansamaeian profile image
Ryan-samaeian

You got a point.And js is very powerfull you can do many things with it!
Make animations,cool effects.
But python is always great!

So is php :)

Collapse
hanna profile image
Hanna Author

I really dislike PHP personally, read this article.

Collapse
ryansamaeian profile image

Some comments have been hidden by the post's author - find out more