Hacker News new | past | comments | ask | show | jobs | submit login

JS is a mess, but async messes aren't JS's fault. Async is hard, but also everything just has to be async -- there's no way around this really. If you write sync code and later you need it to be async, then you're in for a full rewrite. If you write async code and you later need a sync version then you just add a wrapper that waits for completion.

In a world of fast CPUs, slow memory, distributed computing (whether client/server or peer-to-peer), remote function as a service, ..., asynchrony is a hard requirement.

The GUI event model has been with us since... even before the days of X11. Asynchrony in the UI is and long long has been a hard requirement. Users hate synchronous UIs, and rightly so.

Asynchrony is also difficult. But it's not like sync + threads is a panacea -- it's not because threads are way too heavy-duty. Better to deal with the pain than to deny the need.




>If you write sync code and later you need it to be async, then you're in for a full rewrite

If you just want it not to block using the page then you can just chain the sync code into a bunch of async callbacks. For actually parallelizing tasks that weren't before, it can be harder, but in my experience still not a full rewrite. It is much harder for larger applications in other contexts like the migration of Firefox to Quantum, though, yes.


Rubbish! You could make the same argument for parallelising, abstraction, logging, and just about every other feature. But then you’d never build anything because there are infinite possible features you could include.

Build only what you need today, and prepare for what your employer says you will need tomorrow. Anything else is like saying everybody should buy a jeep in case they move to the countryside.

Async brings its own costs. Unless your employer benefits, you are costing them money by giving them features they don’t need.


You have to think at least a bit ahead. Better to write thread-safe async code from day 1 than to rewrite later.


YAGNI - https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it

I’ve worked with plenty of valuable apps not using async. If the requirements change such that async becomes the best way to solve the problem, that’s something the business would decide at that point.


Sometimes you can think ahead and see the need coming -- or not coming -- and act accordingly.

Experience is helpful here.

When I have to write C I try to at least write thread-safe C close to something I could expose as a library. I've had too many cases where I or someone else wrote code they NEVER thought would be needed as a library, therefore took all sorts of liberties, and then suddenly there was a need for a library to do what said code was doing. Oops. I've run into fewer instances of sync code that turns out should really have been async and where adding threads isn't good enough, but I've still run into some.

This isn't about functionality -- this is about scalability. When you know you need to scale, you have to think ahead about it.


A lot of projects are little more than crud with a few complicated business rules. Use a framework with a good caching layer, and a lot of the time the employer is very happy with the outcome. It’s cheap to build, maintain, and host.

But then along comes a developer who says “we must build this app with async so we can scale”. Suddenly the junior devs build an absolute mess because they don’t know how to work effectively with async. So a few seniors get involved. Then the project runs out of cash.

Sure, some projects benefit from async and some fundamentally require it. But not all of them, I doubt even the vast majority of them.

You only need to scale when you’re successful, and most applications are not successful.


"JS is a mess, but async messes aren't JS's fault"

Still though, JS is a mess.


Oh, no doubt!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: