Re:“Node.js is one of the worst things to happen to the soft...
by int_19h on Tuesday August 23, 2016 @01:27AM
(#12341597)
Callbacks are ugly when you have to deal with them directly. But a little bit of syntactic sugar to capture the current continuation as a callback - such as C# await, or the now-repurposed yield in Python - makes it very easy and straightforward to write callback-based async code.
Re:“Node.js is one of the worst things to happen to the soft...
by davidjnelson on Tuesday August 23, 2016 @02:54AM
(#12341875)
Babel and regenerator let you use await in es/js too.
Re:“Node.js is one of the worst things to happen to the soft...
by flamedoge on Tuesday August 23, 2016 @02:56AM
(#12341881)
Python does have await from asyncio
Re:“Node.js is one of the worst things to happen to the soft...
by int_19h on Wednesday August 24, 2016 @03:59PM
(#12354769)
Apparently, I wasn't paying as much attention to the state of async in Python 3.5 as I should have. Looks like they actually have the most featureful implementation of that right now, complete with async for all constructs where it can be sensibly implemented and provide some benefits (like for-loops and with-blocks).
Re:“Node.js is one of the worst things to happen to the soft...
by jackweirdy on Tuesday August 23, 2016 @05:19AM
(#12342379)
Fortunately JavaScript is a flexible enough language that you don't only have to use the primitives it provides.
Promises (which were pure JS before they were ever added to the language) are a more-composable structure for reasoning about concurrency. I don't think I've put more than one line of callback-style code into production per month.
Re:“Node.js is one of the worst things to happen to the soft...
by Klathmon on Tuesday August 23, 2016 @05:40AM
(#12342460)
And async/await are such a game changer its amazing.
I finally bit the bullet and tried it even though it's still not final syntax, it simplified most of my code while keeping the execution exactly the same.
It really is a night and day difference.
Re:“Node.js is one of the worst things to happen to the soft...
by azernik on Tuesday August 23, 2016 @01:13AM
(#12341553)
On the subject of nice higher-level concurrency abstractions, I'm very taken with the current fad for Promises/Futures (a la ES6 or Scala), which are basically a translation of the Haskell IO monad to plain English.
Re:“Node.js is one of the worst things to happen to the soft...
by gclaramunt on Tuesday August 23, 2016 @02:17PM
(#12346046)
Isn't closer to the Async monad?
They certainly make sense from an implementation perspective (I've got this interpreter and I want to do concurrency... I know, I'll just use it to trampoline callbacks).
But callbacks are too low level to reason about easily to some extent, it's kind of like writing everything as a series of goto statements. Sure you can do it, but good luck following it.
The advantages of asynchronous execution are lost. This isn't limited to nodejs, I've experienced similar problems with Python twisted...
Channels (such as in clojure/core.async) or lightweight processes and messaging (such as in erlang/beam), are much more enjoyable to work with.
This shouldn't really be a shock, however, they're higher level abstractions based on real computer science research by people who really thought about the problem.