"Jonathan M Davis" <jmdavisp...@gmx.com> wrote in message news:mailman.214.1331187413.4860.digitalmar...@puremagic.com... > On Thursday, March 08, 2012 00:52:57 Nick Sabalausky wrote: >> "Ary Manzana" <a...@esperanto.org.ar> wrote in message >> news:jj94mb$1i7v$1...@digitalmars.com... >> >> > Here's something I wrote today: >> > >> > parent_ids = results.map{|x| >> > x['_source']['parent_ids']}.flatten.uniq.compact >> > Hash[Site.find(parent_ids).map{|x| [x.id, x]}] >> >> When you format it like that (that is to say, when you *don't* format >> it), >> yea, it's unreadable. Which is why I do such things like this: >> >> parent_ids = >> results >> .map{|x| x['_source']['parent_ids']} >> .flatten.uniq >> .compactHash[ >> Site.find(parent_ids).map{|x| [x.id, x]} >> ] > > I actually tend to find code like that hard to read, because all of the > operations are inside out in comparison to normal. But since the only > difference between his example and yours is the formatting, I agree yours > is > easier to read. Still, I'd much prefer if such code didn't use UFCS, since > I > find it much harder to read that way. It's just so backwards. >
Aside from the problems of excess paren nesting, I tend to think this is backwards: foo(bar(baz(x+2))) ...because the order it's read/written is the complete opposite of the order of exectution. First "x+2" is evaluated, then "baz", then "bar", then "foo". Ie, it's executed right-to-left even though you read/write it left-to-right. Completely backwards. Contrast that with: (x+2).baz().bar().foo() ...which we may be less accustomed to (unless you think of it like bash piping), but in addition to the decrease in nesting, it's written and read in the *same* order as exection: left to right. This also means that it's no longer the complete reverse of statements which are (sensibly) left-to-right: y = x+2; baz(); bar(); foo(); If I were writing code in Arabic, I would probably like "foo(bar(baz(x+2)))". (I would also wonder "What a minute, when did I learn Arabic? How did I manage to learn a langauge without even knowing? This is really weird! But fun. Wheee!!")