Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSL vs. method chaining? #4

Open
joem opened this issue Aug 8, 2013 · 8 comments
Open

DSL vs. method chaining? #4

joem opened this issue Aug 8, 2013 · 8 comments

Comments

@joem
Copy link

joem commented Aug 8, 2013

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?

@jgabrielygalan
Copy link

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.

@DouweM
Copy link

DouweM commented Aug 8, 2013

Using a DSL inside a block is more Ruby-like though.

@joem
Copy link
Author

joem commented Aug 8, 2013

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.

@ryan-endacott
Copy link
Owner

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.

@svineet
Copy link

svineet commented Aug 17, 2013

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.

@ryan-endacott
Copy link
Owner

@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.

@svineet
Copy link

svineet commented Aug 19, 2013

@ryan-endacott , Thanks :)
I tweaked the library now.

@svineet
Copy link

svineet commented Aug 19, 2013

Now both DSL and method chaining are supported(I've only tested the URL test on README and it works :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants