The Pebble in the Ruby Shoe

R

Robert Parker

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).

Anyone who has serious difficulty with 0 based arrays should consider
other employment. Food waiting, bar tending or similar would be a
better choice.
 
S

Sy Ali

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.

Well.. I do enough testing that I usually catch this oversight.. urr
undersight and work around it. I try to accept it because I'm no
mathematician, it's not my call to make and I'm a regular person and
not a real programmer so I don't matter.. but secretly I want to punch
supporters 0 times in the nose and kick them 0 times in the nuts.

I hope I'll get used to 0-based arrays one day. Urr.. zero day.

;)

For the comedy-deficient, that was comedy.

It's still unnerving to work with a 0-based array, because while I
begin counting with zero.. I don't attach any content to that
empty-count. For me, to say there are 0 items is to not begin
counting. It's as though a piece of me expects the 0 in an array to
be nil and for it to never house useful data. I'll get over it
though.

And to argue that rewriting things "is impossible now" isn't quite
correct. It's impossible _now_ but it's possible for Ruby 2.0 isn't
it? Crazy, but possible.
 
P

Peña, Botp

RnJvbTogUmFwaGFlbCBHaWxsZXR0IFttYWlsdG86ci5naWxsZXR0QHJhdGlvbmFsLmRlbW9uLmNv
LnVrXSANCiMgUnVieSBhaW1zIHRvIGJlIGEgaHVtYW4gZnJpZW5kbHkgcHJvZ3JhbW1pbmcgbGFu
Z3VhZ2UgdGhhdCANCi4uLg0KIyBUaGUgcGViYmxlIGluIHRoZSBSdWJ5IHNob2UgaXMgdGhlIGNv
dW50ZXItaW50dWl0aXZlIHVzZSBvZiANCiMgaW5kZXhpbmcgb2YgZWxlbWVudHMgb2YgYXJyYXlz
LCBzdHJpbmdzLCBldGMuLCBmcm9tIDAgdG8gbi0xIA0KIyBpbnN0ZWFkIG9mIHRoZSBtb3JlIG5h
dHVyYWwgMSB0byBuLiAgIA0KDQphbiBvbmVzIHByZWZlcmVuY2UgZXZvbHZlcywgc28gZG9lcyBo
aXMga25vd2xlZGdlIG9mIG51bWJlcnM6IGZyb20gY291bnRpbmcsIHRvIGludGVnZXJzLCB0byBy
YXRpb25hbHMsIHJlYWxzLCBhYnN0cmFjdCwgZXRjLi4NCg0KcnVieSBpcyBxdWl0ZSBlbmNvbXBh
c3NpbmcuIGFycmF5IGluZGljZXMgYXJlIGludGVnZXJzOiBuZWdhdGl2ZSwgemVybywgcG9zaXRp
dmUsIGFuZCB0aGUgcmFuZ2VzIHRoZXJlb2YuLi4NCg0KaXJiKG1haW4pOjAwMTowPiBhPVsxLDIs
M10NCj0+IFsxLCAyLCAzXQ0KaXJiKG1haW4pOjAwMjowPiBhWzBdDQo9PiAxDQppcmIobWFpbik6
MDAzOjA+IGFbLTFdDQo9PiAzDQppcmIobWFpbik6MDA0OjA+IGFbMV0NCj0+IDINCg0KaXJiKG1h
aW4pOjAwNjowPiBhWzAuLjJdDQo9PiBbMSwgMiwgM10NCmlyYihtYWluKTowMDc6MD4gYVswLi4t
Ml0NCj0+IFsxLCAyXQ0KDQp0aHVzIGZvciBtZSwgd2l0aCBydWJ5LCB0aGUgc2hvZSBmaXRzLCBh
bmQgaXQgZml0cyB3ZWxsLg0KDQpraW5kIHJlZ2FyZHMgLWJvdHANCg0K
 
R

Robert Dober

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 ?.."

Should array indices start at 0 or 1? My compromise of 0.5 was
rejected without, I thought, proper consideration. -- Stan
Kelly-Bootle
No I do not believe so, your approach was accepted only that, instead
of the arithmetic mean, the geometric mean has eventually been chosen.
You have a lot of merit in this compromise and I want to thank you on
behalf of the Ruby Community.
Robert
 
F

Frank Church

Ruby aims to be a human friendly programming language that embodies the
principle of least surprise. However, there is an important feature of
the language that, despite being a glaring exception to this laudable
goal, seems to have crept unquestioned into the Ruby core. It is a
rebarbative and truly medieval practice which everyone knows causes
endless confusion, countless unnecessary errors, and a great deal of
wasted programming time in all languages that incorporate it, e.g., C,
Java. In violation of Ruby's ethos, this feature is present purely to
suit the compiler/interpreter at the expense of the person.

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).

Is this some kind of troll?

My own experience with programming makes me feel that counting arrays
from 0 is the natural thing. If you are handling an array 5 items
starting from x, going from x+0 to x+4 is more concise than going from
x+1-1 to x+5-1. There are other examples in which I have found it
convenient.

Chinese count birthdays starting with the child's first year as year
1. As a westerner do you consider it natural describe a child as 2
years old on its "first" birthday?

It may be counterintuitive but in the mathematical world it is quite natural.
 
R

Robert Dober

Is this some kind of troll? Possibly, however...

My own experience with programming makes me feel that counting arrays
from 0 is the natural thing. If you are handling an array 5 items
starting from x, going from x+0 to x+4 is more concise than going from
x+1-1 to x+5-1. There are other examples in which I have found it
convenient.
So is mine, but here eventually ;) my Ada background comes in handy,
we are used to declaring our own bounderies.
I believe that all is habit, but being used to 0 makes life easier I believe.
We could also argue about the values #times is yielding, right;)
Chinese count birthdays starting with the child's first year as year
1. As a westerner do you consider it natural describe a child as 2
years old on its "first" birthday?
You see, all habit, and it shows some intellectual short sight to
dismiss ideas foreign to our paradigm -- that's why I am doing it all
the time ;).
It may be counterintuitive but in the mathematical world it is quite natural.
Or maybe common would be a better world;
In Austria where I went to school 0 is not a positive number. In
France I am constantly confronted with the notation that a whole
number is either positive or negative defining 0 of being part of the
former, drives me crazy, but makes lots of texts much shorter -- they
seem never to use natural number for positive including 0.

But maybe some learned francophone mathematician can mail me off list,
I am only working with engineers, natural as an engineer, you know ;)

Cheers
Robert
 
R

rio4ruby

Anyone who has serious difficulty with 0 based arrays should consider
other employment. Food waiting, bar tending or similar would be a
better choice.

As a former bartender, I take umbrage at this remark. We all used zero
based indexing.
 
R

Robert Dober

As a former bartender, I take umbrage at this remark. We all used zero
based indexing.

Ah please I'd like half a glass #{of_whatever_liquid}, but the upper
half of the glass.
I'd probably not dare asking that in any bar.

Gosh I am OT,OT,OT, sorry folks nobody else to talk to ;)
R
 
F

Florian Frank

Raphael said:
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.

The avalanche has already started. It is too late for the pebbles to vote.
 
A

Adrian Howard

Ok, I know that this is not a Ruby point, but I feel compelled to
respond. The basic array in Pascal is zero based.
[snip]

Fortran doesn't care much either. There's a convention for starting
at 1, but the language allows you to specify an arbitrary index range
for your arrays.

Adrian
 
J

James Edward Gray II

Ok, I know that this is not a Ruby point, but I feel compelled to
respond. The basic array in Pascal is zero based.
[snip]

Fortran doesn't care much either. There's a convention for starting
at 1, but the language allows you to specify an arbitrary index
range for your arrays.

Perl copied that misfeature, though it defaults to zero, in the hopes
of attracting Fortran programmers. What they learned was that it
breaks way too much. I'm pretty sure it's being removed in Perl 6.

James Edward Gray II
 
R

Robert Dober

Wait a second are you sure?

type my_array = array[<somerange>] of <sometype>;

It was up to you, right? Maybe you are talking of some dialects or did
I really forget??
<snip>
 
A

Adrian Howard

Tim Pease wrote:
Actually, if Ruby had been implemented in Fortran or Pascal,
then most
certainly arrays would have begun indexing with 1 instead of 0.

Ok, I know that this is not a Ruby point, but I feel compelled to
respond. The basic array in Pascal is zero based.
[snip]

Fortran doesn't care much either. There's a convention for
starting at 1, but the language allows you to specify an arbitrary
index range for your arrays.

Perl copied that misfeature, though it defaults to zero, in the
hopes of attracting Fortran programmers.

Perl's misfeature is pretty different - it's a global rather than a
per-array thing. Being able to say "this particular array has indices
-10 -> 10 is considerably more useful than saying "every array starts
at -10" :)
What they learned was that it breaks way too much. I'm pretty
sure it's being removed in Perl 6.

It is. Everybody admits it was a bad idea.

Adrian
 
Y

Yossef Mendelssohn

On 16 Jul 2007, at 19:22, Lloyd Linklater wrote:
Tim Pease wrote:
Actually, if Ruby had been implemented in Fortran or Pascal, then
most
certainly arrays would have begun indexing with 1 instead of 0.
Ok, I know that this is not a Ruby point, but I feel compelled to
respond. The basic array in Pascal is zero based. [snip]

Fortran doesn't care much either. There's a convention for starting
at 1, but the language allows you to specify an arbitrary index
range for your arrays.

Perl copied that misfeature, though it defaults to zero, in the hopes
of attracting Fortran programmers. What they learned was that it
breaks way too much. I'm pretty sure it's being removed in Perl 6.

James Edward Gray II

I spent plenty of time trying to explain to people the difference
between using an array in scalar context (to get the number of
elements) and using the "end of array" sigil (to get the last index).
I don't recall seeing people check $#array against -1 to see if the
array was empty, but I remember plenty of iterating over 0 .. @array -
1.

Of course, never did I (seriously) tell people to use $[ .. $#array.
That would work no matter what, but I preferred to think of it as a
test case. If some module I'm using changed array indexing, let me
know. I'll never use it again.
 
M

M. Edward (Ed) Borasky

Adrian said:
Ok, I know that this is not a Ruby point, but I feel compelled to
respond. The basic array in Pascal is zero based.
[snip]

Fortran doesn't care much either. There's a convention for starting at
1, but the language allows you to specify an arbitrary index range for
your arrays.

Adrian
FORTRAN wasn't always that way. The ability to index arrays starting at
some value other than one came fairly late in the language -- at least
FORTRAN I, II and IV only started at 1. Does anyone here remember what
it was in Algol 60? It must have been 0, since most languages that don't
allow an arbitrary starting index are descended from Algol 60 and use 0.

I should go look that up. :)
 
B

brabuhr

FORTRAN wasn't always that way. The ability to index arrays starting at
some value other than one came fairly late in the language -- at least
FORTRAN I, II and IV only started at 1. Does anyone here remember what
it was in Algol 60? It must have been 0, since most languages that don't
allow an arbitrary starting index are descended from Algol 60 and use 0.

I should go look that up. :)

I never used ALGOL, but:

http://en.wikipedia.org/wiki/ALGOL_58
Both IAL and ALGOL 60 allowed arrays with arbitrary lower and upper
subscript bounds, and allowed subscript bounds to be defined by
integer expressions.

http://www.cs.virginia.edu/~mpw7t/cs655/pos2.html
ALGOL 68 was designed to be an improvement upon ALGOL 60. In ALGOL 60,
arrays could be multi-dimensional, they could be dynamically sized,
and their lower bound index could be non-zero [1].
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,100
Latest member
MelodeeFaj
Top