verbal_expressions
verbal_expressions copied to clipboard
DSL vs. method chaining?
This isn't so much an 'issue' as it simply 'something to consider':
I noticed that this is one of the only (if not the only) implementation listed on the organization page that doesn't use method chaining for the start_of_line()
, find()
, maybe()
, etc. methods...
I wonder if it might be better to follow the original's method chaining strategy instead of this DSL approach? I'm pretty sure there are things possible with method chaining that you can't do with the DSL (although admittedly I'm not sure if any of it's actually useful). Also, it might make it easier to translate and keep up with any possible changes to the other versions if it were more closely following their implementations.
What's your take?
Not that I'm advocating one way over the other, but using method chaining instead of using a block would allow to use reserved words such as "then", "or" and so on.
Using a DSL inside a block is more Ruby-like though.
DSLs have indeed become an inherent part of Ruby culture and I don't want to sound like I'm DSL-bashing, but I'm not sure if I'd agree that a DSL inside a block is more Ruby-like than method chaining. Using DSLs is a programming pattern that the community has adopted due to the ease of implementation in the language, whereas method chaining is a built-in feature of the language.
I did originally use the DSL because it felt more Rubyist, but I think that the decision could be revisited.
@jgabrielygalan, that's another valid point I hadn't considered. It would be nice to have the reserved words.
@joem, As far as keeping up with the other versions, most of the implementation stays the same (besides the reserved words). After the initial DSL setup, everything was ported line-by-line. With a few slight modifications, it could be made to work with chaining or the DSL, but I'm not sure that's what we should do.
The DSL also offers some extra benefits. For example, it makes the capture
syntax possible. Without it, you would have to create an entirely new VerEx
object for nesting. There may be another way to get around that by messing with the scope of evaluation, but nothing immediately comes to mind.
I feel like the DSL is cleaner and fits better for a Ruby library, but that's just my personal opinion.
Hey, just for fun, I tried implementing a method chaining VerEx Ruby package. It's only one file and not by any means complete, May have many bugs, but still passes the URL testing example on the README. Here it is.
@saivineet89, very cool! You actually may be able to tweak the existing library to make it work with chaining and then everything else will work the same.
@ryan-endacott , Thanks :) I tweaked the library now.
Now both DSL and method chaining are supported(I've only tested the URL test on README and it works :)