Hi.
I am a big fan of programming in point-free style, although
unfortunately Ruby makes that unnecessarily ugly. I.e., I very much
prefer
ary.each(&method(:puts))
over
ary.each {|el| puts el }
The reason for this is the old saying by Phil Karlton:
| There are only two hard problems in computer science. Cache invalidation and
naming things.
If naming things is hard (i.e. expensive), then names shouldn't be
wasted on irrelevant things. And conversely, if something has a name,
then it is important.
The whole *point* of higher-level iteration methods like
Enumerable#each and friends is to lift collection operations over the
individual elements, IOW to make the individual elements not
important; ergo, the individual elements shouldn't need to be named.
However, today there was a StackOverflow question about the efficiency
of such point-free code, especially with regards to reified Method and
Proc objects.
Personally, I don't care. I have yet to see Object#method or
Method#to_proc even show up in any profile.
My first reaction was basically that any halfway decent Ruby execution
engine should be able to inline and optimize the point-free version
all the way back till it generates basically the same machine code as
the explicit one. However, I am now having second thoughts about
whether there are some aspects of the semantics of Method and Proc
objects that make it impossible for them to be as efficient as a
method call (which after speculative inlining typically ends up as
just a conditional jump).
Since Rubinius seems to be the most advanced and most aggressively
optimizing Ruby execution engine, I thought I'd ask here:
1. Does Rubinius currently optimize such point-free code?
2. If it doesn't, could it?
3. If it could, should it?
Thanks in advance!
Greetings,
jwm
--
--- !ruby/object:MailingList
name: rubinius-dev
view: http://groups.google.com/group/rubinius-dev?hl=en
post: [email protected]
unsubscribe: [email protected]