Bye Bye JavaScript Promises
sriku.org
sriku.org
If you still end up using Javascript at the end of the process, hey, great, go nuts, but after years of swaggering optimism in the JS community about how somehow their stuff was so much better than anybody else's despite "event-based code" being extraordinarily well-trodden ground since the 1990s (as in being the default programming model for all serious code and entire major dominant operating systems), it might be worth people taking a moment to consider whether some more listening at the beginning of the process might have cut some years off this journey of discovery. The Javascript community has not been leading the charge of writing asynchronous code... they just caught up.
Over-exuberance sometimes requires admonishment, especially when there is such a colossal waste of energy and effort like in the JavaScript "community" (OP's word, but still...). If JavaScript programmers spent more time listening and reading and less time posting "so I wrote my own" blogs we might have had things like Reactive libraries for JavaScript years ago.
Throwing a word like "hate" around tells me you're likely too young to really understand what that means.
Also, you picked on his tone and let the Go comment slide? Really?
In short, get seasoned, dude.
Even I, (young, unseasoned) know that criticism, admonishment and even a little "I told you so" do not equal hate.
Ugh, that word.
Sure, the abstraction isn't leaky... Because there is barely an abstraction at all. Synchronizing state between independent processes is a very real, very unfun problem when all you have is the actor model.
For what it's worth, all of Facebook.com fetches its data with async/await (effectively promises+data) which is a nice sweet spot and a lot better to work with than actors.
FWIW I like CSP, but promises are great for e.g. fetching data
2. Promise.prototype.bind 4. You can put try / catch / finally anywhere. It doesn't have to be in the end, but it does have to be close to what you want to wrap (just like any other try / catch).
Coming form a large node project where I have been spending the better part of my waking hours for several weeks closing memory leaks caused by holding onto closures indefinitely, I would advise against the sort of meta programming advised in this article.
var text = yield fs.readFile.bind(null, '/file.txt')You can achieve what you're doing without any macros, with better throw safety, better debugging traces and more.
Yes but No.I personally think macros are the "root of all evil". Because they just make languages unreadable. That's one thing to have a complete different language that compiles down to JS,but as soon as you introduce macros is your code you make it harder to understand and document.I'm glad it works for you,but in my opinion the use of macros should be banned.While limited to nodejs, I personally think fibers are better alternative.
4. I actually think that it makes promises elegant. You can chain 20 then and have a single catch in case things are wrong,but you need to adjust the logic accordingly.Using different Error "classes" and checking the type is usually what I do.
I still believe promises are an elegant way to deal with async programming,and ES6 lambdas will make them even less painfull.
I'm not sold on generators for async programming strangely ,for multiple reasons(lack of support in browser land,especially on mobile).
EDIT: macros are fine in LISP likes because it's not like these languages have a complex syntax. And in C,well you cant program without them. My point is javascript has enough features to make macros unnecessary.
Don't get me wrong. They can hurt a codebase such that it is not readable anymore. But you know, functions can do similar. Heck, for some code basees, the same thing.
From the wikipedia:
"Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures"
All of these things are certainly possible in ruby, see [0] fizzbuzz in the lambda calculus in ruby
I don't know if I agree or not.
But the moment you name a block (pass it to a method with a named block argument) or create one with "proc" or "lambda" or "Proc.new", the form you get access to it in is a Proc object, and calling it is a method call (ob.call).
The distinction is quite pointless, other than as an implementation artefact for MRI, as there shouldn't be any obvious observable differences in behaviour between a bare block and a Proc (in my "eternally in progress and not very functional yet" Ruby compiler, all blocks are in fact Proc instances, though if you can tell, it's a bug)
"The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed. It must first be retrieved into a Method or Proc object to be used as first-class data. The syntax for calling such a function object differs from calling regular methods. Nested method definitions do not actually nest the scope."
You can certainly make the case that Ruby has first-class functions, but they don't feel very first-class in practice.
"However, as we confront increasingly complex problems, we will find that Lisp, or indeed any fixed programming language, is not sufficient for our needs. We must constantly turn to new languages in order to express our ideas more effectively. Establishing new languages is a powerful strategy for controlling complexity in engineering design; we can often enhance our ability to deal with a complex problem by adopting a new language that enables us to describe (and hence to think about) the problem in a different way, using primitives, means of combination, and means of abstraction that are particularly well suited to the problem at hand."
https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-25.htm...
lisp/scheme have macros that understand the structure of the code in a more fundamental way; they're more a feature of the language than a pre-processing step.
please explain .
Kinda like CancellationToken in .Net, I guess.
Consider changing the 'font-family' to 'monospace'?