DSLs and metaprogramming
hackerengineer.net
hackerengineer.net
Ruby meta-programming uses runtime flexibility to do cool things, but has_many is just a method, like any other method, which is passed arguments (at runtime), and can do super-cool things with them because of the late-binding architecture of Ruby. This a concept originated from Smalltalk. It's super cool.
Lisp macros do something completely different: they let you extend the parser of the language. They literally let you write code that edits your code, at compile time, before anything is run. It's super cool, too, but in a very different way.
Here's a hig-level view:
1) You write code.
2) That code is translated to a data structure which is interpreted by a computer.
Lisp macros are ways of extending what the translation rules are. Ruby, on the other hand, has lots of neat design decisions which let you write code that interprets instructions at runtime in interesting ways. Very different.
Is that right for me as a developer?
When you do meta-programming using Ruby, you're writing code that is executed at run-time (and can use runtime data). When you're writing Lisp macros, you're literally writing a code pre-processor: a bunch of little programs that walk over your code and expand it to other code before execution begins.
A great question is what the relative limitations are of both. I don't have a definitive answer, but I think this is one of the fundamental questions software engineering should attempt to answer - what abstractions can we build at compile-time, and what abstractions must be left for run-time?
I'm not very comfortable picking sides like that - they're different things (as I said in the other post - horses and bicycles). Which is better for creating abstractions is a very difficult question, which I don't think we quite have the vocabulary to ask correctly.
So when do you run into problems with Ruby? Can you give some samples of code that demonstrate the problem, and how lisp's macros avoid it? And, does something like this (http://news.ycombinator.com/item?id=948454) fix the issue on the ruby side?
Thanks!