DEV Community

Michael Capecci
Michael Capecci

Posted on

Where does Python Shine Over Node?

This is the scenario I'm in:

I'm comfortable with Node, I have interest in Python but little experience, and I want to begin writing scripts for automating certain processes on my local machine.

At first glance, Node is capable of handling any task that Python would be used for, but Python is often touted as the "go-to" choice for this type of work.

I'd like to know what others think about this, and maybe some specific areas that Python would be a better choice than Node.

Thanks for reading.

Top comments (7)

waylonwalker profile image
Waylon Walker

Great question. I feel the answer really comes down to the community and the ecosystem. So much of what defines modern language is its ecosystem of packages, and people. If you are most productive using node then use it. There is no reason that you need to use one or the other. If there are packages in the other that might make your work easier that is a valid reason to check it out.

Each has its niche. I don't think that anyone is going to be starting up a data science shop running nodejs anytime soon. There just isn't the pool of talent to hire from for it. Could you do Data Science in nodejs, absolutely. Is it likely that there are successful people out there that are far more productive writing data science in nodejs, probably. It you want to build a team or be hired on a team you need to be where the community is. Sometimes both have a strong community, other times there is a clear winner.

pencillr profile image
Richard Lenkovits

More of a python vs javascript comparison here. Backstory: I'm using node for my personal projects and webapps, and I'm using python (+bash) in my DevOps dayjob.

I'd say that after you learn it, you'll see that python is a much more elegant and robust language as it didn't have to endure the whims and fancies of the web world for several years - compared to javascript. A few years ago I picked up javascript after python, so I was the other way around, but here's a few things I felt python was better at:

  • Great native functional style tools like list comprehension, and generators
  • No undefined and null just None
  • A great type system with lists, sets, tuples, dictionaries. ( Javascript types are not so versatile. No mutable/immutable distinction, no built-in hash-table support, confusing implicit type evaluation. )
  • No semicolons. Transparent code structure through indentation based function boundaries.
  • No mess with let, const, var, just a very clean function scope (global is heresy).

  • The only downside I see is maybe the package management with pip and virtualenv, which could be a bit hard to grasp and setup at first. But after that I thing generally python modules are safer compared to the dumpsterfire at npm. :)

patarapolw profile image
Pacharapol Withayasakpunt • Edited
  • Not sure if Python can make anything immutable, though -- unlike top-level const
  • Although Python has function scopes, Python's loop famously leaks its scope.
  • List comprehension / generator expressions are indeed nice and maybe performant, but they can be hard to read sometimes. Otherwise, I never like how we write map(), filter().

Otherwise, you are right that Python is generally safer.

Personally, I don't like Python anymore, due to its namespace full of common words by default...

vitalykrenel profile image
Vitaly Krenel • Edited

Hey @duhdugg ! Thanks for the great clarification on the technical details! I don't have Python experience, while mostly working on with JS/Node and PHP/Ruby world, so it was quite interesting to read that Python is not implementation itself, but CPython is.

I was wrongly assuming, for some reason, that Python is a self-hosted language, but now when I think that I heard about IronPython and CPython before, it makes sense - so those are not complier ports, but rather implementations. Should have explored this long ago, silly me. Thanks, you let me gather together those pieces in my head πŸ˜…

Continuing on the @mjcapecci question, I'm also curious about product use cases where Python as backend language would be a preferred choice over JS on the backend. I.e. the advantages of the two from the business side.

If you have experience working with both Python and Js and backend developer, would be interesting to hear for what type of project you would use Python over JS (excluding personal tastes and language proficiency).

For example, you might consider criteria like the speed of development, ecosystem size, language innate performance, maybe some other things.

Would be interesting to hear πŸ™‚

gwutama profile image
Galuh Utama

I think it depends on your goals. I mainly use Python for replacing bash because it’s easier to maintain Python source code as opposed to bash scripts. For my use case Python is perfect because I know that the interpreter is installed by default on mac and linux and so I can just run the script without having to install anything, except when my Python script uses non-standard libraries, which is quite seldom.

I think Python is more popular in data science, AI and image processing due to libraries and bindings such as tensorflow, numpy, scipy, pandas, opencv, etc. being available officially for python. Some of these libraries are also available on npm but they are not official ones so support from the package mantainers is kind of questionable.

Iβ€˜d say if js and node can fulfill your goals just fine, then you should use them.

mjcapecci profile image
Michael Capecci

Interesting. Yes, of course I understand that Node is not a language, but rather the environment that one can utilize JS to complete OS-level tasks that are comparable to those that Python is often used for.

This is kind of what I suspected of Python - a more robust environment of well-tested modules for doing things that a lot of people have already wanted to do. Plus, potentially an easier implementation due to not worrying about async.

mjcapecci profile image
Michael Capecci

This is all really interesting stuff about target environments. I also was under the impression that, once you installed Python or enjoyed having it by default on your Mac or Linux machine, that it just simply ran in and of itself.

What are the implications on target environment when you setup a virtual environment (venv)? I wonder if this is using CPython behind the scenes.