3 ms·
All this async stuff should die as soon as possible. It exposes the limitations of the underlying tech and forces the application developer to deal with things
by jacquesm 6y ago
All this async stuff should die as soon as possible. It exposes the limitations of the underlying tech and forces the application developer to deal with things that the systems level people couldn't bother with.
Look at the Erlang eco-system to see how this is done the right way.
Threads, asynchronicity, locks and so on should be dealt with at the OS or the framework level, not at the application level.
Javascript also suffers from this and it makes JS ugly and hard to read. Callback hell will be yours or you end up with crutches such as promises.
At the application level things should be as deterministic as possible and the default should be that statements executed in sequence will have their side effects updated in sequence as well.
- speedgoose 6y agoThanks to the async/await keywords, modern javascript is not a callback hell anymore.
- jacquesm 6y agoNo, now you get it all mixed up. One library will use callback functions you supply, another will use callbacks but inline them and yet another will use async/await. And you, the application developer are left somewhere in the middle. Oh, and you can't use 'await' in the main thread of your JS, you can only use it from within another async function, so when you need it most - for instance during application start-up - it isn't available.
- speedgoose 6y agoYou can use promisify for the first one. For the second one I think these libraries doing that but still not supporting promises are not that common anymore but nothing you can't do with promises yourself. Javascript has a single thread, but I see what you mean and it has been fixed recently. To support older versions you can simply declare an anonymous async function and execute it immediately.
- doubleunplussed 6y agoI think of it the other way around: Thanks to javascript being single-threaded, we now have async/await keywords strewn throughout the software ecosystem where they provide no benefit.
- war1025 6y agoAsync is basically a super convenient way to interact with an event loop. Any time you call `await` you are saying "schedule an event on the event loop, and call back into this method with the result once it's available" Multi-threaded code is good for some things, but often you need an event loop to keep things reasonable (GUI code for example). That's where async / await really shines.
- anonymoushn 6y agoThis is pretty unfortunate. I expect that if JS had gotten fibers and a switch primitive, other languages would have copied that, but now users of unrelated languages are stuck with low-quality things forever.
- mywittyname 6y agoYeah, but now we have this weird mix of awaits, thens, and missing awaits that you're not sure were intentional. I may be in the minority here, but I kind of prefer callback hell to async hell. It's fine on projects with one or two devs, but more than that and the situation seems to devolve into tabs-vs-spaces, where one group finds the other incomprehensible and won't use it.
- cturner 6y agoExposing the limitations of the underlying tech is a good thing, because it makes it clear what needs to be fixed. Early operating system APIs grew up around batch systems, which were inherently synchronous. As multi-user systems and networking became ubiquitous, computers have become inherently asynchronous. But system APIs have been slow to evolve, or else have made explicit decisions to go all-in with threading (e.g. WinAPI). Threads are a paper-over. You can use threads to simulate asynchronicity over synchronous system APIs. As I'm sure you know, threads have a widespread performance tax (context switching blowing out your cache), and are an obstacle for the developer who wants to understand exactly what the machine is really doing. When you use async, you can reason about what the machine is doing. Operating system APIs have been slow to effectively support this. For example, they usually support something like select(3) but it's usually non-trivial to check for keyboard input in the same select call as you are checking for network activity. It's encouraging to see Linux add io_uring recently. I think I have read elsewhere that Windows is your main platform. Indeed, the Windows API steers programmers heavily towards threads due to design choices. Sometimes in linux you can hack in a path towards async by abusing file descriptors+threads but Windows is inflexible here. Tanenbaum defends the synchronous model, "Parallel programming and interrupts are REALLY REALLY hard to get right. There are all kinds of race conditions you have to worry about. Synchronous is much safer. Sometimes there is no way around using an asynchronous interface, but it is always the last resort. Making it hard to do is a good idea." But the RMOX os seems to have solved the general problem of creating a pure-async system api. The dialects of Javascript that are in the current generation of browsers are confusing partly because the async model in that js generation is half-baked. In another comment, you highlight the ecosystem problems that have grown around js callback hell. But these problems are not an inherent problem of async programming. For example, python3 asyncio does not suffer from callback hell, because (1) it is straightforward to await on a coroutine to return a value, and (2) the ecosystem has grown up around a mature async model. There are still hassles with python asyncio libraries that use threads under the hood. For example, I've had trouble with aiofiles at scale. Regarding Erlang: I see the actor model as a weak response to multicomputing. Some of the difficult problems of that domain: (1) message reliability; (2) grid-application survival when you lose a physical host. Erlang/Actor avoids responsibility here by telling the application programmer that they must assume that message delivery is unreliable. This pushes handling of all related problems into the application layer, where it is a distraction, and arduous to test. I think the actor model dodges hard problems that are inherent to its chosen domain. (Apologies if I have misunderstood the reason you highlighted Erlang.)