From: John Joyce Date: 2007-07-17T00:21:33+09:00 Subject: Re: The Pebble in the Ruby Shoe On Jul 16, 2007, at 8:58 AM, Michael Ulm wrote: > Raphael Gillett wrote: >> 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. 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). > > I, for one absolutely hate 1 based arrays in programming languages. > It creates a thousand little problems that one has to program around. > Ruby got it Right (again). > Every language does things the way the language designer wants to do it. see this article for some discussion on it: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html AppleScript also uses 1 based arrays. The practicality of any of several approaches is largely subjective. Ideally there would be a flag to set the type of indexing you want to use. In Ruby, you could certainly do something to implement it, but it would cast some overhead unless you created something like class Array1 to be analogous to class Arrray, just indexed from 1 instead. Feel free to create it and see if it would get added in. It might certainly be useful as an option for some people, but in general it is pretty simple to adjust between the paradigms. Work the way a language works, don't try to make it work the way another language works. Many people, myself included, were first confounded by this in C, but you adapt quickly. 0 indexing is convenient in that the element equal to the length is out of bounds or contains a special character/marker to denote the end of the array, depending on the language. Some things are just continued because of convention. Most languages use 0-based indexing.