3 ms·
I use both JS and Python professionally. Overall, I prefer JS, but I also see plenty of nice things about Python. Here's my comparison: (Full disclosure with a
by alangpierce 9y ago
I use both JS and Python professionally. Overall, I prefer JS, but I also see plenty of nice things about Python. Here's my comparison:
(Full disclosure with all of this: I haven't spent as much time researching Python tools as JS tools, and I'd love to hear if I'm wrong with any of this.)
Nice things about JS:
* The state of type systems is much more mature. TypeScript and Flow are both well-maintained language extensions that make it practical to have full type coverage, and both provide language servers for nice autocomplete in any editor. It has been a while since I've tried Python type annotations and mypy, but my understanding is that they aren't at the same level.
* The tooling seems to be better overall. npm and yarn seem to be more well-thought-out than pip and virtualenvs and better handle version pinning and avoid dependency hell. ESLint seems to give much higher-quality results than flake8, and has many autofixers. I recently set up Prettier at work, and people have felt that it significantly improves their coding process and have asked if I could set up the same thing for Python. The answer I have to give is "no, because nothing like Prettier exists for Python".
* Object destructuring (and related features) is probably the biggest language feature that I miss when I'm coding in Python. Tuples and namedtuples both feel much more awkward to work with than JS objects.
* JS has block scoping. It's amazing how many times I've seen a loop assignee or list comprehension variable wreak havoc in Python because of a name clash with some other variable, and that problem simply doesn't happen in JS.
* JS (like almost all languages except Python) allows statements within expressions, so you can pass in a callback lambda function with non-trivial code in it. Python context managers (`with` statements) and decorators seem to cover many of the common use cases for code-within-a-function-call, but I still run into cases in Python where it feels like I need to awkwardly work around the language.
* The JS import system seems better-thought-out. Circular imports tend to be a big problem for us in Python, but not in JS.
Nice things about Python:
* List comprehensions are nice to write and read. In JS you use `map` and `filter`, which isn't so different in theory, but I still like list comprehensions better.
* Python makes it much less of a pain to work with complex types, e.g. having a dict where the keys are tuples. In JS, plain object keys must be strings, and the newer Map type only allows identity equality for keys, so you need to find workarounds.
* Keyword args are nice.
* Python's approach to method instance binding is more intuitive. You never have to worry about `self` not being correct, whereas every new JS programmer need to go through a phase where they learn how to make sure `this` is correct. (Newer JS features like arrow functions make this less of a concern.)
* Python is more likely to fail fast when you make a mistake (e.g. accessing a nonexistent property due to a typo), whereas JS is more likely to fail silently.
* While Python and JS both have a "dark history" and plenty of legacy warts, Python has fewer of them. But I consider both to be pretty minor: Python 3 fixes a lot of things, and pretty much any reasonable ESLint config disallows code using problematic older JS features (like `var`, `for...in`, and global assignment).