Ruby DSL Handbook
11–20 of 30 posts
Re: Ruby DSL Handbook
#12I think it needs a foreword: "your problem likely is nowhere near needing a DSL, please don't write one just because it makes you look clever". Signed: everyone who's ever used a DSL which could have been written better as a couple of dozen functions.
Re: Ruby DSL Handbook
#13Is there some kind of sample chapter?
Re: Ruby DSL Handbook
#14I've never been a fan of using "DSL" in the context of Ruby. Sure, you can do some metaprogramming, but you cannot create new syntax, change order of evaluation, etc., which I feel is a fundamental requirement for creating real EDSLs. One simple consequence of this is that you end up having to quote a lot of things.
Re: Ruby DSL Handbook
#15I think it needs a foreword: "your problem likely is nowhere near needing a DSL, please don't write one just because it makes you look clever". Signed: everyone who's ever used a DSL which could have been written better as a couple of dozen functions.
Almost any problem can be meaningfully and usefully solved by introduction of a DSL. It's a remarkably flexible technique. Ruby is a really bad language to write good DSLs in. Metaprogramming is an awkward replacement for better DSL facilities. Maybe this book can demonstrate better techniques?
Re: Ruby DSL Handbook
#16I've never been a fan of using "DSL" in the context of Ruby. Sure, you can do some metaprogramming, but you cannot create new syntax, change order of evaluation, etc., which I feel is a fundamental requirement for creating real EDSLs. One simple consequence of this is that you end up having to quote a lot of things.
This surprises me. Can you offer an example of those types of problems in some Ruby code?
attr_reader foo
The 'foo' above would evaluate to the contents of the variable 'foo'. So, you have to do this: attr_reader :foo
Because we cannot control how this code evaluated, we must quote 'foo'. This greatly limits what we can express.Re: Ruby DSL Handbook
#17I think it needs a foreword: "your problem likely is nowhere near needing a DSL, please don't write one just because it makes you look clever". Signed: everyone who's ever used a DSL which could have been written better as a couple of dozen functions.
Re: Ruby DSL Handbook
#18Earlier quoted context omitted.
This surprises me. Can you offer an example of those types of problems in some Ruby code?
Let's use 'attr_reader' as a simple example. It defines a method that returns the value of a member variable. It would be nice to refer to the variable name literally, but this is not possible: attr_reader foo The 'foo' above would evaluate to the contents of the variable 'foo'. So, you have to do this: attr_reader :foo Because we cannot control how this code evaluated, we must quote 'foo'. This greatly limits what w…
[:foo, :bar].each do |attribute|
attr_reader attribute
end
You probably wouldn't want do actually do that with attr_reader, but it is just an example.Re: Ruby DSL Handbook
#19Earlier quoted context omitted.
This surprises me. Can you offer an example of those types of problems in some Ruby code?
Let's use 'attr_reader' as a simple example. It defines a method that returns the value of a member variable. It would be nice to refer to the variable name literally, but this is not possible: attr_reader foo The 'foo' above would evaluate to the contents of the variable 'foo'. So, you have to do this: attr_reader :foo Because we cannot control how this code evaluated, we must quote 'foo'. This greatly limits what w…
Re: Ruby DSL Handbook
#20I think it needs a foreword: "your problem likely is nowhere near needing a DSL, please don't write one just because it makes you look clever". Signed: everyone who's ever used a DSL which could have been written better as a couple of dozen functions.
how about: every DSL should be a thin translation layer over a clean API. Too many times I've been burned by gems that provide a DSL and there's no other way to use their functionality.