On Oct 1, 2007, at 2:58 PM, Chad Perrin wrote:

> On Mon, Oct 01, 2007 at 03:25:37AM +0900, 7stud -- wrote:
>> Here's a simple test for the op.  Which of the following do you  
>> think is
>> easier to understand?  Can you guess what each program does?
>>
>> language1:
>> --------
>>
>> colors = ["red", "blue", "green"]
>>
>> colors.each {|color| puts color}
>>
>>
>> language2:
>> ---------
>> colors = ["red", "green", "blue"]
>>
>> for color in colors:
>>     print color
>
> In the case of someone who has never programmed before, I rather think
> "colors.each {|color| puts color}" might be less confusing than "for
> color in colors:\n  print color".  I have never in my life seen  
> anything
> in plain English that even began to look like "for color in  
> colors", and
> the meaning of that clause is non-obvious.  Meanwhile,  
> "colors.each" at
> least looks like it's saying something about each of something,  
> with the
> "each" attached obviously to the "colors", suggesting that it's saying
> "for each element of the colors array".
>
> The only way the Python one looks anything like "more intuitive" to
> someone who has never encountered Ruby or Python before, as far as  
> I can
> tell, is if that person is familiar with C.
>
> -- 
> CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
> They always say that when life gives you lemons you should make  
> lemonade.
> I always wonder -- isn't the lemonade going to suck if life doesn't  
> give
> you any sugar?
>
But you forget, Ruby can also do
colors = Array.new # Or Hash.new, etc...

for color in colors
   puts color
end

This format makes more sense to some people in some cases. Seems  
pretty clear. For some it is more clear than the .each version with  
its do-end or {}
Of course, if they don't get used to do-end and {} they'll have a  
hard time with Ruby...