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

Reduce duplication with Processor::API::Responder #7

Closed
wants to merge 4 commits into from

Conversation

snusnu
Copy link
Owner

@snusnu snusnu commented Jul 11, 2013

@dkubb @mbj @solnic

I'm opening a PR for this because I wanted to get your input. Do you consider this a worthy change? It feels like reducing duplication like this, results in more complexity. Even though flog doesn't show an increase, I do consider the code added in Processor::API::Responder to be more complex than the previously present duplication. Also, flay count didn't decrease either.

I somewhat think that I still like the code in this PR more than the previous version, but I wanted to get your thoughts on a decision like this.

Thx!

# @api private
def define_abstract_helper_method(host)
host.class_eval do
define_method(:respond_with) do |_klass, _output|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use abstract_type to remove some of this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkubb not really, as i also include that module into non-abstract classes which provide an implementation of #respond_with (Substation::Request)

@snusnu
Copy link
Owner Author

snusnu commented Jul 11, 2013

I had to use class_eval to make ruby-2.0 happy and now the flog score "even" increased. I guess that's not so bad after all, I just wanted to mention it.

@solnic
Copy link

solnic commented Jul 11, 2013

I don't like that. Lots of unnecessary meta-programming. You also didn't remove duplication, you just replaced 2 similar lines of code with much more complex code. Not worth it IMHO.

@snusnu
Copy link
Owner Author

snusnu commented Jul 11, 2013

as discussed in irc, i tend to agree with @solnic ...

@dkubb
Copy link

dkubb commented Jul 11, 2013

Actually, thinking about it from that pov I agree with @solnic.

I was more or less just thinking that maybe this pattern was repeated in lots more places, or would be, then I wouldn't have an issue with it. If all this work is just to remove two lines of code then maybe it should be skipped.

@snusnu
Copy link
Owner Author

snusnu commented Jul 11, 2013

@dkubb yeah, as i mentioned in irc, initially i thought it would be usable in those 2 places PLUS be useful to substation clients too. Turns out i was wrong with that latter assumption. While it could be used by substation clients, there's already a nicer, more straightforward way of doing something to the same effect (if you're interested, I'm talking about this: https://github.com/snusnu/substation/blob/master/spec/app.rb#L112-L118)

Also, there's another argument against this. The code actually dynamically defines public api methods, which robs me of the possibility to properly document those. That's fairly severe I guess.

I'll wait for @mbj to chip in, but currently, I lean towards nuking that branch and happily move forward using current master.

EDIT: typo

@snusnu
Copy link
Owner Author

snusnu commented Jul 11, 2013

I just want to drop one more (mostly useless) comment. Metaprogramming is just programming after all. The code still does nothing more than define three methods, but it does it once now. The "ceremony" needed for the meta part in metaprogramming can be considered complex, but i guess there are other ways to look at that too.

@dkubb
Copy link

dkubb commented Jul 11, 2013

Yeah, I don't really make too many distinctions between programming and metaprogramming. I can read and understand what both examples do without too much effort.

In terms of complexity the original code is probably simpler. Still, it's not like it's doing anything we haven't seen before.. this is a fairly common pattern in some of the support libs we're using. I think the original is probably clearer in terms of intent though. And there are likely other ways to DRY it up that may end up being simpler.

@snusnu
Copy link
Owner Author

snusnu commented Jul 17, 2013

It's just not worth it ....

@snusnu snusnu closed this Jul 17, 2013
@snusnu snusnu deleted the processor-api-responder branch July 31, 2013 23:48
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

Successfully merging this pull request may close these issues.

None yet

3 participants