5 ms·
tldr; macros 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
by aikah 12y ago
tldr; macros
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.
- taeric 12y agoThis seems overly restrictive. Especially when, at a base level, macros should be easier to explain than some alternatives. It is quite literally, "take this and replace it with that." 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.
- aikah 12y agoI'd argue that sweetjs actually changes JS syntax,which is not the case with some other languages that have macros. If JS had Ruby's blocks, there would be no need for sweetjs. But I've heard TC39 wants to introduce macros in the future,so you might have them anyway...
- davexunit 12y agoRuby blocks are a poor substitute for a macro system. JavaScript already has something better than Ruby blocks anyhow: first-class functions.
- deleted 12y ago[deleted]
- pselbert 12y agoRuby certainly has first-class functions. Not only can you pass "functions" around as lambdas or procs, you can also detach and re-atach methods from a class or object at runtime. 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 [0]: https://gist.github.com/tomstuart/1466504 https://gist.github.com/tomstuart/1466504
- lucian1900 12y agoSome consider Ruby blocks to not be first-class functions since calling them is different from calling methods. I don't know if I agree or not.
- vidarh 12y ago"Bare" Ruby blocks are called differently from calling methods (yield). 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)
- davexunit 12y agoFrom the same Wikipedia article: "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.
- davexunit 12y agoI don't think you understand the ability for macros to make code more readable. "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.html https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-25.htm...
- aikah 12y agosee the edit.I still think they are unecessary in javascript.
- ploxiln 12y agoI've used C a lot, and while you do need macros sometimes, IMHO it's best to use them as minimally as possible. So I'm in agreement. 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.
- deleted 12y ago[deleted]