Hi --

On Fri, 30 Jun 2006, Omer Raviv wrote:

> John Johnson wrote:
>
>
>> IIIEEEeee, it's Perl, it's Perl!  :-)
>>
>> I don't see anything wrong with:
>>
>> [1, 2, 3].all? { |n| n > 0 }
>>
>> It's a lot more legible than getting into all the Snoopy talk (@#$%).

I agree.  I don't see the problem with it.

> I agree that it's fine, but:
>
> a) It can be expressed with a shorter code snippet (less line noise),
> therefore making it easy to do method-chaining.

"&:>" and such, I would argue, are shorter but have *more* line noise
than the equivalent explicit blocks.

> b) I implicitly understand that it is an array of numbers, so the idea
> of "a number" repeats itself three times (you had to write 'n' twice).
>
> a better example might be:
> all_people.select { |person| person.retired? }
> The subject of this operation is expressed twice more than it ought to
> be.
>
> Therefore,
>
> [1,2,3].all?(:>, 0)
> and
> all_people.select(:retired?)

I always think of these things partly in terms of explanation.  In
order to explain all_people.select(:retired?), one would either have
to present :retired? as a "magic" way of filtering for retiredness, or
explain that it's actually {|p| p.retired? } in disguise.  Somehow it
doesn't work as, so to speak, a primary, transparent technique.

"Why is there a colon?"  Because it's a symbol.  "So a symbol invokes
the method of that name?"  No.

And so on....


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

See what the readers are saying about "Ruby for Rails"!
http://www.rubypowerandlight.com/quotes