Hacker News new | ask | show | jobs
by rtpg 1284 days ago
JS suffers way too much from a lack of a good comprehensive standard library and builtins. It doesn't even have list comprehensions!

I get thinking Python and JS are "kind of the same", but there are so many details that Python gets right and JS kinda falls apart on. Python's pervasive dunder methods means that you can look at objects in a REPL and get a good representation (try looking at any non-trivial Javascript object and it's a major pain). You can define equality. Operations _don't_ stringify by default (so dictionaries work like you think they should). And Python has blocking methods, which means that you can write code in a straightforward way.

There are a lot of things playing in JS's favor but especially as packaging stories get better it's hard to discount Python's ease of use relative to Javascript IMO. And all of this is kind of ignoring the fact that most people are _actually_ talking about Typescript when they talk about JS nowadays, because writing "raw" JS is so error prone that it would be very difficult to actually get serious work done in it without an extra lint phase (I say this as a huge TS proponent)

1 comments

> It doesn't even have list comprehensions!

JS actually did used to have list comprehension but it was deprecated because nobody used it. There's no need imo. .map, .filter, .reduce, and other array methods achieve the same thing with a nicer syntax imo

Also JS has undoubtedly one of the nicest anonymous function syntax with arrow functions. Something I constantly find myself missing when I'm in a python file.

> And Python has blocking methods

What does this mean? Isn't JS blocking by default? Both languages have async support that you don't have to use...

> it's hard to discount Python's ease of use relative to Javascript

Hmm I guess we just have different experiences with this. I can open up a quick text file anywhere on my computer, save it as a .ts file, import whatever library I want, use TS if I want it, etc and then just run it in the CLI with `deno run test_run.ts`

Feels pretty easy to me. And then you have _anything_ related to UI. Maybe it's just me but I never quite felt comfortable with GUI libraries in Python. With JS I can just make an HTML file and open it up in any browser and I have access to the most cross-platform UI API in the world: the WWW

> "raw" JS is so error prone that it would be very difficult to actually get serious work done in it

If you're trying to get "serious" work done you probably shouldn't be using either of these languages. Or if you are, you'd definitely have some linter set up for either one. Also, Python's typehints are nice, but it can't compare to TS. And if you don't wanna go all in on TS, you could always stick with JSDoc comments which get you 90% of the way there for small projects and have really great support in any modern IDE.

> What does this mean? Isn't JS blocking by default? Both languages have async support that you don't have to use...

To be clear on this, because JS APIs prioritize non-blocking mechanism to the expense of everything else (related to it the original sin of how JS interacts with a browser IMO), everything has to become async, even though in practice a lot of this stuff is happening sequentially anyways.

See this example Playwright test [0]. awaits everywhere. Because of how await works as well (Rust got this one right with postfix await), suddenly fluent APIs become awkward. You no longer have foo.bar().baz() but (await foo.bar()).baz(). (await getResources()).map(f) is not beautiful in my eyes.

And the core thing is that almost no code actually relies on concurrency in practice! So much of this is a consequence of the problem of JS not having good yielding semantics, and its interaction with the DOM in general.

Is this the biggest issue in the world? I guess not, but I very much dislike the aesthetics of this fore smaller chunks of code. I would really like a model with implicit awaiting in ~all the places that it exists currently.

I do agree that JS's anonymous function syntax is nice, and I miss it dearly in Python. Though here as well, I think Python comes up on top with all of its argument/keyword argument strategies. I get the options dictionary pattern, but dislike it.

And UI stuff is of course ... well it's easier in Javascript (though it requires its own infrastructure). There's no ways around that.

Loads of serious work is done in both language, I just think that JS is missing a lot of table stakes features given that there's so much attention to it.

[0]: https://playwright.dev/docs/writing-tests#the-example-test