This post originated from an RSS feed registered with Ruby Buzz
by Phil Tomson.
Original Post: Please ignore the wizard behind the curtain
Feed Title: Thoughtfiz
Feed URL: http://wiki.railsplayground.net//xml/rss/feed.xml
Feed Description: Thoughtfiz: lots of tiny thought bubbles, mostly Ruby-related.
As I said earlier, the more Ruby-ness that can be hidden from the user of RHDL (or any DSL, for that matter), the better. It's not that Ruby is bad, it's mostly an issue of aesthetics and consistency within the DSL as well as hiding details that the user doesn't care about. Consider the following RHDL circuit desciption:
class AndGate < RHDL
inputs a, b
outputs out
define_behavior {
out <= a & b
}
end
If I'm a user of RHDL who doesn't know any Ruby I'm going to think "What the heck is the class AndGate < RHDL all about?"... the wizard is not fully hidden. When designing a DSL we need to anticipate those kinds of questions and proactively eliminate them, so I've eliminated the explicit class definition and replaced it with a def_circuit method:
AndGate = def_circuit {
inputs a,b
outputs out
define_behavior {
out <= a & b
}
}
where def_circuit is defined as follows:
def def_circuit &b
klass = Class.new(RHDL, &b)
#... lots of other code to deal with define_behavior & init blocks ...
#... also, initialize for klass is created here
klass
end
[hmm... I should change define_behavior to def_behavior to save some keystrokes and match def_circuit.]