I think that using this style is certainly possible, but fairly obtuse to most rubyists. If you never wrote blocks and instead only wrote these &method(:blah) isms, the other programmers on your team would get frustrated with you.
That being said, you asked a technical question rather than a stylistic one, so I'll answer it technically. You're assumption that it could be the same as a block is, I'm sad to say, dead wrong. There reason you don't see Method#to_proc and such in profiling is 2 fold: 1) Most (all?) MRI profilers do not show a methods that MRI defines in C, so they'd never show up. 2) The mechanism for activating a method that has been turned into a Proc is all in C, so the overhead is invisible on the invocation side too. You're point about the arty differences are right on. Additionally, you're thinking that a VM could easily optimize it into a block is quite wrong. Object#method is a not specially, not something that would be detected and optimized away. Additionally, even with runtime optimizations, something like escape analysis is still required since #method returns a Method object that you'd have to see inside and extract the information from. On the invocation side, the invoked method can only do something special with the block in the case of block inlining, an optimization that only Rubinius has. So to get to your questions: 1. Does Rubinius optimize this code? No. Could it? Yes, but it's hardly easy. 2. In time it could, yes. 3. In time it should, yes. - Evan -- Evan Phoenix // [email protected] On Monday, August 8, 2011 at 10:06 AM, Rich Morin wrote: > Although I understand your rationale for point-free style, > I should note that it will seem _really peculiar_ to many > Rubyists. It might also cause maintenance issues, if the > maintainer doesn't understand the idiom. > > This may not be a show-stopper, particularly if your code > isn't read or modified by others. However, you should keep > it in mind for any distributed or shared code . > > -r > -- > http://www.cfcl.com/rdm Rich Morin > http://www.cfcl.com/rdm/resume [email protected] (mailto:[email protected]) > http://www.cfcl.com/rdm/weblog +1 650-873-7841 > > Software system design, development, and documentation > > -- > --- !ruby/object:MailingList > name: rubinius-dev > view: http://groups.google.com/group/rubinius-dev?hl=en > post: [email protected] (mailto:[email protected]) > unsubscribe: [email protected] > (mailto:[email protected]) -- --- !ruby/object:MailingList name: rubinius-dev view: http://groups.google.com/group/rubinius-dev?hl=en post: [email protected] unsubscribe: [email protected]
