2011/6/6 Ilias Lazaridis <ilias / lazaridis.com>:
> On 6 =C9=EF=FD=ED, 01:11, Yukihiro Matsumoto <m... / ruby-lang.org> wrote:
>> Hi,
>>
>> In message "Re: CORE - Altering Behaviour of "each do" (default param "i=
tem")"
>> =A0 =A0 on Sat, 4 Jun 2011 20:50:25 +0900, Ilias Lazaridis <il...@lazari=
dis.com> writes:
>>
>> |#Question: How can I alter the behaviour of "each" in the following
>> |way:
>> |names.each do
>> | =A0print item =A0 =A0 =A0 =A0 # "item" is used by default
>> |end
>> |
>> |Is this possible, without going to C-level?
>>
>> It's possible but you have to redefine the each method.
>
> ok
>
>> That reminds me Groovy's it.
>
> I don't know "Groovy", but I dislike the "it", as it cannot be spoken
> like "each item" or "each value".
>
> I've just noticed repetitions within code like that:
>
> names.each { |name| puts name} # 3 times "name(s)"
>
> names.each { puts item }
>
> names.each { puts e) # e =3D entry
>
>> Currently I have no plan to change the core like that.
>
> So this would be a low-priority issue?
>
> Would a thoroughly worked out patch be accepted?

I vote against because I prefer explicit function arguments (block
parameters) over implicit ones.  The approach with the predefined name
only works well for cases where there is a single argument but will
become ugly soon if you need multiple arguments.  Either you need to
use array access (which is worse than using explicit argument names
because those names will make code more readable) or allow mixed mode
(explicit arguments where desired, implicit as default).  I do not
believe that this makes code easier to read and less prone to errors.

Btw, what you call "specification" is just an example of a single use
case.  For a language change the behavior would need to be _uniform_
across the board, otherwise it is plain obfuscation.  As I hope you
are aware there are multiple implementations of #each - and the number
can and will actually change at runtime.  So any change would have to
be applied to all of them - and there is no automatism that could do
it unless you are willing to have a new #each with a different name.

It seems to me that you are suggesting language changes without an
idea of the consequences.  Please do a bit more reasoning before you
come up with such suggestions.

robert


--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/