> Raphael Gillett wrote the following on 16.07.2007 15:22 :
> > [...]
> > The pebble in the Ruby shoe is the counter-intuitive use of indexing of
> > elements of arrays, strings, etc., from 0 to n-1 instead of the more
> > natural 1 to n.   Like prisoners who have got used to their chains, the
> > Ruby community seems to have meekly accepted this impediment to clear
> > thinking.  

Dear Raphael,

from http://www.americanscientist.org/template/AssetDetail/assetid/51982?&print=yes,

 an overview article about the history of around 6000 computer programming
languages:



"Still another perennially contentious issue is how to count. This one brings out the snarling dogmatism in the meekest programmer. Suppose we have a list of three items. Do we number them 1, 2, 3, or should it be 0, 1, 2? Everyone in computerdom knows the answer to that question, and knows it as an eternal truth held with the deepest, visceral conviction. Only one of the alternatives is logically tenable. But which is it ?.."

If you strongly believe that Ruby gets it all wrong, you can do all
the iterations with 

Array.each{|item|  ... } or
Array.each_with_index{|item,i|  ... }  # <= don't need to know where
                          you start counting actually 

> > It is particularly puzzling that Ruby should hobble its
> > users in this way, because it is manifestly unnecessary (e.g., Fortran
> > and Pascal don't do it).

If you check out different wordings of Peano's axioms, which define
the natural numbers, you'll find that they'll work regardless of whether
you name the first element 0 or 1 or 175758, so it's not necessary
to start at 0 or at 1 or anywhere else, but in the implementation
of a programming language, you sometimes have to make a convention choice. 

Ruby, in contrast to some languages I used to work with before
(e.g., Matlab, which is a one-language, or C, which is a zero-language), lets you do your work even if you don't adhere to the convention choice made thanks to the each_with_index method.

Also, sometimes, you could prefer to count still differently:
e.g., January, February ,....


year.each{|month|  p "Have a nice " + month } 

I find that this can increase readability of a program a great deal...


Best regards,

Axel 
-- 
Psssst! Schon vom neuen GMX MultiMessenger geh?rt?
Der kanns mit allen: http://www.gmx.net/de/go/multimessenger