Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The Pebble in the Ruby Shoe

1 view
Skip to first unread message

Raphael Gillett

unread,
Jul 16, 2007, 9:22:05 AM7/16/07
to

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

--
Posted via http://www.ruby-forum.com/.

SonOfLilit

unread,
Jul 16, 2007, 9:30:53 AM7/16/07
to
I disagree. Zero based arrays are natural to a mathematician, and
programmers tend to be mathematicians.

It's humanity that has the wrong clue. I hate the problems that
one-based counting creates. Anywhere, not just in arrays.

Aur

Lionel Bouton

unread,
Jul 16, 2007, 9:31:58 AM7/16/07
to
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. 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).
>
>

It's probably a matter of taste: I'm so used to indices starting at 0
that I would probably create a lot of bugs if I had to use arrays with
indices starting at 1.

For me an index has simply become a distance from the first element of
an array.

Anyway changing this would probably break at least 99% of all Ruby code
out there, so it's not likely to happen, is it?

Lionel.

Sammy Larbi

unread,
Jul 16, 2007, 9:47:10 AM7/16/07
to

Well now would be a hell of a time to change it, wouldn't it? =)


Michael Ulm

unread,
Jul 16, 2007, 9:58:05 AM7/16/07
to
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).

Lloyd Linklater

unread,
Jul 16, 2007, 10:55:24 AM7/16/07
to
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).

Well, why don't you make a new class that uses a hash as an array and
set the range to be from 1..X? A really cool thing about Ruby is that
making such things is simple and encouraged.

Axel Etzold

unread,
Jul 16, 2007, 11:05:46 AM7/16/07
to
> 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

John Joyce

unread,
Jul 16, 2007, 11:21:33 AM7/16/07
to

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.

Bertram Scharpf

unread,
Jul 16, 2007, 11:40:45 AM7/16/07
to
Hi,

Am Montag, 16. Jul 2007, 22:22:05 +0900 schrieb Raphael Gillett:
> 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.

To start indexing of arrays from 0 is any good programmers
-first- sorry zeroth lesson. It is the natural way. Get used
to it.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

Robert Dober

unread,
Jul 16, 2007, 11:50:48 AM7/16/07
to
On 7/16/07, Axel Etzold <AEt...@gmx.de> wrote:
> > 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?

Both ideas are completely stupid, there is only one err zero err 42 solutions.
42, 43, 44

Robert

--
I always knew that one day Smalltalk would replace Java.
I just didn't know it would be called Ruby
-- Kent Beck

Martin DeMello

unread,
Jul 16, 2007, 12:32:28 PM7/16/07
to
On 7/16/07, Axel Etzold <AEt...@gmx.de> wrote:
> > 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

martin

ara.t.howard

unread,
Jul 16, 2007, 1:27:20 PM7/16/07
to

On Jul 16, 2007, at 7:22 AM, Raphael Gillett wrote:

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


and we all know how 'natural' *those* languages are do program in
(ducks)...

a @ http://drawohara.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama


Tim Pease

unread,
Jul 16, 2007, 1:46:25 PM7/16/07
to
On 7/16/07, ara.t.howard <ara.t....@gmail.com> wrote:
>
> On Jul 16, 2007, at 7:22 AM, Raphael Gillett wrote:
>
> > 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).
>
>
> and we all know how 'natural' *those* languages are do program in
> (ducks)...
>

Actually, if Ruby had been implemented in Fortran or Pascal, then most
certainly arrays would have begun indexing with 1 instead of 0.
However, since it was implemented using C, Ruby follows the convention
of implementation.

And we all know how easy it is to program in C ;-)

Blessings,
TwP

Paweł Kraszewski

unread,
Jul 16, 2007, 2:09:50 PM7/16/07
to
> 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

I grew up with 0-based arrays. 1-based ones look unnatural to me. That's the
truth, as for me.

The worst nightmare for me was CHS addressing on disks - Cylinders are
0-based, Heads are 0-based, but Sectors are 1-based. Hell on earth.

That were my 3 cents.


PS.
O, and yes. Welcome everybody! I felt in love with Ruby 2 weeks ago. I find
it much more flexible than Python, my previous love and much more
expressive (and object-oriented) than PERL, my next-to-previous love. I
think Ruby puts the best of all scripting languages together. Gott sei dank
for Yukihiro Matsumoto and his precious mind.

--
Paweł Kraszewski
www.kraszewscy.net

Xeno Campanoli

unread,
Jul 16, 2007, 2:17:41 PM7/16/07
to

I always thought it made more sense to index from zero. After all, an
index represents an offset from the start, and the rest of the aspect is
just a one to one correspondence. The first thing there could as easily
be item Skattlebraught, the second being item Porktail, etc. The
standard of C using 0 as an index happened because it made sense, not
because it was merely different. I think Matz has typically adopted
things that make the most sense, and though some may not be used to
this, I don't find it unclear and it is more rational than starting with
index 1, though it may be less popular among some people. I think we
are always better off considering the adoption of something non-standard
that might be better. After all, if not, we would never have gotten
beyond COBOL and JCL, and we might all be living some "Brazil" Orwellian
nightmare.

>
> Blessings,
> TwP
>
>


--
The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.

Lloyd Linklater

unread,
Jul 16, 2007, 2:22:08 PM7/16/07
to
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.

var
ar: array of integer; // dynamic array
begin
SetLength(ar, 10); // makes a 0 - 9 array
end;

var
ar: array[1..10] of integer; // makes a 1 - 10 array

The default is pretty much zero based, even in Pascal.

matt neuburg

unread,
Jul 16, 2007, 2:39:15 PM7/16/07
to
Raphael Gillett <r.gi...@rational.demon.co.uk> 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

But since Ruby lets you reach right in and override everything, couldn't
you just change this in your own programs if you don't like it?

m.
--
matt neuburg, phd = ma...@tidbits.com, http://www.tidbits.com/matt/
Tiger - http://www.takecontrolbooks.com/tiger-customizing.html
AppleScript - http://www.amazon.com/gp/product/0596102119
Read TidBITS! It's free and smart. http://www.tidbits.com

SonOfLilit

unread,
Jul 16, 2007, 2:52:17 PM7/16/07
to
> > 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
>
> But since Ruby lets you reach right in and override everything, couldn't
> you just change this in your own programs if you don't like it?

Hmm, would probably break the standard library.

But you could inherit from Array.

Aur

Tom Werner

unread,
Jul 16, 2007, 3:05:11 PM7/16/07
to
matt neuburg wrote:
> Raphael Gillett <r.gi...@rational.demon.co.uk> 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
>>
>
> But since Ruby lets you reach right in and override everything, couldn't
> you just change this in your own programs if you don't like it?
>
> m.
>

This seems like a terrible idea. Part of learning a language is learning
the ways that things are done in that language. If a coder starts
rewriting basic methods because of some silly prejudice against
zero-based indices, then that coder has just introduced a huge potential
trap for anyone wanting to modify that code. Some seriously nasty bugs
would almost certainly be introduced until the contributor realizes that
their basic assumptions about the language have been changed. Rewriting
functionality at that level should always be done with a very careful
analysis of how those changes might impact other coders, and the code
that other coders write.

Think before you reimplement.

Tom

John W. Kennedy

unread,
Jul 16, 2007, 6:25:32 PM7/16/07
to
Paweł Kraszewski 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
>
> I grew up with 0-based arrays. 1-based ones look unnatural to me. That's the
> truth, as for me.
>
> The worst nightmare for me was CHS addressing on disks - Cylinders are
> 0-based, Heads are 0-based, but Sectors are 1-based. Hell on earth.

On many disks, there is (or used to be) a sector #0 that is not used for
data; instead, it is used to record information about bad sectors, or
similar things.
--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"

Robert Parker

unread,
Jul 16, 2007, 7:57:43 PM7/16/07
to
On 7/16/07, Raphael Gillett <r.gi...@rational.demon.co.uk> 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).

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

Peter Seebach

unread,
Jul 16, 2007, 8:52:18 PM7/16/07
to
In message <8f6eb7340707161657s7d8...@mail.gmail.com>, "Robert Parker" write
s:

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

I wouldn't go quite that far, but I have to say, I don't think 0-based
indexing is at ALL a bad thing. I agree that it's arguably not perfectly
intuitive, but... Well, that's true of a lot of things, and sometimes
that's because our intuition doesn't work very well.

-s

M. Edward (Ed) Borasky

unread,
Jul 16, 2007, 9:14:50 PM7/16/07
to
Anyone who's been immersed in scientific computing for any reasonable
length of time will probably be equally at home in both 0-based and
1-based indexing. I don't know about business computing, though, because
I haven't done a lot of it. I think those folks got a smack in the face
when decimal computers withered away, though. :)

Sy Ali

unread,
Jul 16, 2007, 9:46:48 PM7/16/07
to
On 7/16/07, Raphael Gillett <r.gi...@rational.demon.co.uk> 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.

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.

Peña, Botp

unread,
Jul 17, 2007, 12:00:18 AM7/17/07
to
From: Raphael Gillett [mailto:r.gi...@rational.demon.co.uk]
# Ruby aims to be a human friendly programming language that
...
# 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.

an ones preference evolves, so does his knowledge of numbers: from counting, to integers, to rationals, reals, abstract, etc..

ruby is quite encompassing. array indices are integers: negative, zero, positive, and the ranges thereof...

irb(main):001:0> a=[1,2,3]
=> [1, 2, 3]
irb(main):002:0> a[0]
=> 1
irb(main):003:0> a[-1]
=> 3
irb(main):004:0> a[1]
=> 2

irb(main):006:0> a[0..2]
=> [1, 2, 3]
irb(main):007:0> a[0..-2]
=> [1, 2]

thus for me, with ruby, the shoe fits, and it fits well.

kind regards -botp

X1

unread,
Jul 17, 2007, 12:20:49 AM7/17/07
to
Agreed.

The pebble is a ruby :-)

Sent from my iPhone

On Jul 17, 2007, at 12:00 AM, Peña, Botp <bo...@delmonte-phil.com>
wrote:

Pete Yandell

unread,
Jul 17, 2007, 1:32:47 AM7/17/07
to
Don't feed the trolls.

Religion, wannabe game programmers, and now this! The list is driving me
nuts this past week.


Pete Yandell
http://notahat.com/

Robert Dober

unread,
Jul 17, 2007, 1:47:06 AM7/17/07
to
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.

Frank Church

unread,
Jul 17, 2007, 1:58:11 AM7/17/07
to
On 16/07/07, Raphael Gillett <r.gi...@rational.demon.co.uk> wrote:
>
>
> 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).
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

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.

Robert Dober

unread,
Jul 17, 2007, 2:10:15 AM7/17/07
to
On 7/17/07, Frank Church <voi...@googlemail.com> wrote:
> On 16/07/07, Raphael Gillett <r.gi...@rational.demon.co.uk> wrote:
> >
> >
> > 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).
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> >
> >
>
> 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

rio4ruby

unread,
Jul 17, 2007, 5:09:38 AM7/17/07
to
On Jul 16, 4:57 pm, "Robert Parker" <rlp1...@gmail.com> wrote:

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

Robert Dober

unread,
Jul 17, 2007, 5:48:57 AM7/17/07
to
On 7/17/07, rio4ruby <Christophe...@gmail.com> wrote:

> 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

Brad Phelan

unread,
Jul 17, 2007, 6:29:25 AM7/17/07
to

Now Pete you beat me to the comment ;)

--
Brad Phelan
http://xtargets.com

Florian Frank

unread,
Jul 17, 2007, 7:14:14 AM7/17/07
to
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.

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

--
Florian Frank

Adrian Howard

unread,
Jul 17, 2007, 8:58:35 AM7/17/07
to

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.

Adrian

James Edward Gray II

unread,
Jul 17, 2007, 9:27:17 AM7/17/07
to

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

Robert Dober

unread,
Jul 17, 2007, 9:30:31 AM7/17/07
to
On 7/17/07, Adrian Howard <adr...@quietstars.com> wrote:
>
> 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.
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]
<snip>

Adrian Howard

unread,
Jul 17, 2007, 9:43:35 AM7/17/07
to

On 17 Jul 2007, at 14:27, James Edward Gray II wrote:

> On Jul 17, 2007, at 7:58 AM, Adrian Howard wrote:
>
>>
>> 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.

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

Yossef Mendelssohn

unread,
Jul 17, 2007, 9:54:48 AM7/17/07
to

On Jul 17, 8:27 am, James Edward Gray II <ja...@grayproductions.net>
wrote:

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.

--
-yossef

--
-yossef


M. Edward (Ed) Borasky

unread,
Jul 17, 2007, 11:19:20 AM7/17/07
to
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. :)

bra...@gmail.com

unread,
Jul 17, 2007, 12:53:22 PM7/17/07
to
On 7/17/07, M. Edward (Ed) Borasky <zn...@cesmail.net> wrote:

> Adrian Howard wrote:
> > 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.
>
> 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].

Lloyd Linklater

unread,
Jul 17, 2007, 2:44:27 PM7/17/07
to
Florian Frank wrote:

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

Oh my Kosh!

Chad Perrin

unread,
Jul 17, 2007, 3:03:31 PM7/17/07
to
On Tue, Jul 17, 2007 at 10:43:35PM +0900, Adrian Howard wrote:
>
> 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" :-)

News to me. Would you point me at more information on the topic, please?

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
Ben Franklin: "As we enjoy great Advantages from the Inventions of others
we should be glad of an Opportunity to serve others by any Invention of
ours, and this we should do freely and generously."

M. Edward (Ed) Borasky

unread,
Jul 17, 2007, 11:33:41 PM7/17/07
to
bra...@gmail.com wrote:
> 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.

I wonder how C got saddled with a fixed lower limit of 0 then. It must
have been a simplification somewhere in the chain from Algol - CPL -
BCPL - B - C.

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

Algol 68 was a truly marvelous language that somehow never caught on.


Giles Alexander

unread,
Jul 18, 2007, 12:15:02 AM7/18/07
to
On 7/18/07, M. Edward (Ed) Borasky <zn...@cesmail.net> wrote:
> I wonder how C got saddled with a fixed lower limit of 0 then. It must
> have been a simplification somewhere in the chain from Algol - CPL -
> BCPL - B - C.

In C the expression array[n] is actually just syntactic sugar for
*(array + n). Literally. I haven't tried in years, but the following
is supposed to be legitimate: n[array]. Great for obfuscating code.

If that's how you're going to perform array lookups, then your array
indices have to start from 0.

Giles

kevin cline

unread,
Jul 18, 2007, 3:16:26 AM7/18/07
to
On Jul 16, 8:22 am, Raphael Gillett <r.gill...@rational.demon.co.uk>

wrote:
> Ruby aims to be a human friendly programming language that embodies the
> principle of least surprise...

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

With 50+ years of collective experience, it seems clear that zero-
based arrays lead to the simplest code.

Ronald Fischer

unread,
Jul 18, 2007, 3:42:21 AM7/18/07
to
> In C the expression array[n] is actually just syntactic sugar for
> *(array + n). Literally. I haven't tried in years, but the following
> is supposed to be legitimate: n[array]. Great for obfuscating code.

This indeed works, and consequently funny variations such as
(n1-n2)[n2+array] work too. It is obfuscating not so much because
it were not easy to understand, but because we simply are not used to
see it written that way (because other languages usually do it in
the other way around).

To contrast with, the IMO most unpleasant way of approaching the index
origin was done in APL. There, you could set the system variable _IO
to either 0 or 1 (no other value accepted), which rules whether array
the index of *any* array is from now on counted from 0 or from 1.
True, you *could* localize this setting in a function, but at least
in original APL (I don't know about APL2), these were not truly
"local" variables like in Ruby, but more like those "local global"
variables you would for example declare in Perl by writing
'local $v=....;', with the consequence that they the change to _IO
would be visible in all functions called from within the function
which had "locally" reset the index origin. This has the consequence
that if you write *any* reusable function for APL (such as a library),
you must use the value of this variable for indexing. For example,
in order to access the Nth element of an array A, you would write
something like A[N+_IO-1].

BTW: Though I - like most programmers - find it most convenient counting
arrays from zero, there are cases where I would find it more natural
if I could choose the upper and lower bound of an array by myself (as
it is done in languages such as Ada). Such an approach would work well
in a statically typed language (where you can in principle look up
the variable declaration), but would make understanding a program
unnecessarily hard in dynamic languages such as Ruby.

Ronald

MenTaLguY

unread,
Jul 18, 2007, 4:03:45 AM7/18/07
to
On Wed, 2007-07-18 at 16:42 +0900, Ronald Fischer wrote:
> To contrast with, the IMO most unpleasant way of approaching the index
> origin was done in APL. There, you could set the system variable _IO
> to either 0 or 1 (no other value accepted)

Perl has this too, though it's called $[.

Obviously, it isn't normally used and people assume the default value of
0. :)

-mental

signature.asc

MenTaLguY

unread,
Jul 18, 2007, 4:05:34 AM7/18/07
to
On Wed, 2007-07-18 at 16:20 +0900, kevin cline 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.
>
> With 50+ years of collective experience, it seems clear that zero-
> based arrays lead to the simplest code.

That's been my personal experience, too -- pretty much the only thing
1-based indices make simpler is getting the last element of an array
given its size; everything else seems to get more complex.

-mental

signature.asc

Ronald Fischer

unread,
Jul 18, 2007, 4:33:11 AM7/18/07
to
> > To contrast with, the IMO most unpleasant way of
> approaching the index
> > origin was done in APL. There, you could set the system
> variable _IO
> > to either 0 or 1 (no other value accepted)
>
> Perl has this too, though it's called $[.
>
> Obviously, it isn't normally used and people assume the
> default value of
> 0. :)

True! It seems that the Perl community (reasonably) assumes
that whoever fiddles with $[, so everyone assumes it to be
0, while in the APL world it was more common to expect that everyone
might change _IO...

Ronald

Robert Dober

unread,
Jul 18, 2007, 7:54:36 AM7/18/07
to
I do not like categorical statements, but this one might be the
exception that confirms the rule.
+1 (or was that +0 ;)
Robert

Michael P. Soulier

unread,
Jul 18, 2007, 9:45:34 AM7/18/07
to
On 18/07/07 Robert Dober said:

> I do not like categorical statements, but this one might be the
> exception that confirms the rule.
> +1 (or was that +0 ;)

Lets not forget also that doing things for the sake of being different help no
one. I for one must work in multiple languages. I still haven't forgiven Matz
for the whole, "0 is true" thing. ;-)

Mike
--
Michael P. Soulier <msou...@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It
takes a touch of genius - and a lot of courage to move in the opposite
direction." --Albert Einstein

Robert Dober

unread,
Jul 18, 2007, 9:56:09 AM7/18/07
to
On 7/18/07, Michael P. Soulier <msou...@digitaltorque.ca> wrote:
> On 18/07/07 Robert Dober said:
>
> > I do not like categorical statements, but this one might be the
> > exception that confirms the rule.
> > +1 (or was that +0 ;)
>
> Lets not forget also that doing things for the sake of being different help no
> one. I for one must work in multiple languages. I still haven't forgiven Matz
> for the whole, "0 is true" thing. ;-)
That is the single best feature of Ruby once you got used to it --
with "" is true!!!
IMHO of course.

M. Edward (Ed) Borasky

unread,
Jul 18, 2007, 10:32:12 AM7/18/07
to
Well ... the reason the first major programming language, FORTRAN, used
1-based indexing is that it was designed for scientific computing, which
uses matrices extensively. And a matrix in a textbook or research paper
almost always has row and column indices ranging from 1 to N. So ... one
of the things 1-based indexing makes simpler is thinking about matrices.

Assembly language programming, at least on binary machines, is a lot
more natural with 0-based indexing, since that's the way the hardware is
laid out.

M. Edward (Ed) Borasky

unread,
Jul 18, 2007, 10:42:53 AM7/18/07
to
Michael P. Soulier wrote:
> On 18/07/07 Robert Dober said:
>
>> I do not like categorical statements, but this one might be the
>> exception that confirms the rule.
>> +1 (or was that +0 ;)
>
> Lets not forget also that doing things for the sake of being different help no
> one. I for one must work in multiple languages. I still haven't forgiven Matz
> for the whole, "0 is true" thing. ;-)
>
> Mike

I haven't forgiven Scheme for "nil is true" either!! That's just *so*
wrong to a Lisp 1.5 programmer.

Robert Dober

unread,
Jul 18, 2007, 12:04:40 PM7/18/07
to
On 7/18/07, M. Edward (Ed) Borasky <zn...@cesmail.net> wrote:
Much more difficult to see the benefits of this, but I am listening ;)

R.

John W. Kennedy

unread,
Jul 18, 2007, 1:05:33 PM7/18/07
to

...unless there is a lot of exposure of nominal index values to the end
user, in which case the additional effort of doing that may incur more
complexity than is saved by using 0-origin internally.
--
John W. Kennedy
"The bright critics assembled in this volume will doubtless show, in
their sophisticated and ingenious new ways, that, just as /Pooh/ is
suffused with humanism, our humanism itself, at this late date, has
become full of /Pooh./"
-- Frederick Crews. "Postmodern Pooh", Preface

John W. Kennedy

unread,
Jul 18, 2007, 1:11:13 PM7/18/07
to
M. Edward (Ed) Borasky wrote:
> Well ... the reason the first major programming language, FORTRAN, used
> 1-based indexing is that it was designed for scientific computing, which
> uses matrices extensively. And a matrix in a textbook or research paper
> almost always has row and column indices ranging from 1 to N. So ... one
> of the things 1-based indexing makes simpler is thinking about matrices.

> Assembly language programming, at least on binary machines,

...all the decimal machines I can recall, too...

> is a lot
> more natural with 0-based indexing, since that's the way the hardware is
> laid out.

PL/I implementations have historically regarded the address of an array
as being where the (0, 0, 0...) element would be, even if one doesn't
exist, to reconcile these two.

--
John W. Kennedy
A proud member of the reality-based community.

Lloyd Linklater

unread,
Jul 18, 2007, 1:55:13 PM7/18/07
to
Michael P. Soulier wrote:
> Lets not forget also that doing things for the sake of being different
> help no one. I for one must work in multiple languages. I still haven't
> forgiven Matz for the whole, "0 is true" thing. ;-)

but but but...

The original idea of zero as true, if memory serves, is that a function
can return a result based on whatever it was doing. It was assumed that
there was one way to get everything to run right but many ways to fail.
SO, if you have zero as the true and everything else as both an
pass/fail indicator AND telling you just what the problem was, then true
= zero makes a good deal of sense.

my $0.02

MenTaLguY

unread,
Jul 18, 2007, 2:04:14 PM7/18/07
to
On Wed, 2007-07-18 at 22:56 +0900, Robert Dober wrote:
> > Lets not forget also that doing things for the sake of being different help no
> > one. I for one must work in multiple languages. I still haven't forgiven Matz
> > for the whole, "0 is true" thing. ;-)
> That is the single best feature of Ruby once you got used to it --
> with "" is true!!!

One of the biggest advantages to this is that it makes || and ||=
actually useful for non-boolean stuff (by way of contrast, Perl has the
same operator behavior, but it's not as useful when common valid values
can be false).

-mental

signature.asc

Robert Dober

unread,
Jul 18, 2007, 4:04:31 PM7/18/07
to
On 7/18/07, MenTaLguY <men...@rydia.net> wrote:
> On Wed, 2007-07-18 at 22:56 +0900, Robert Dober wrote:
> > > Lets not forget also that doing things for the sake of being different help no
> > > one. I for one must work in multiple languages. I still haven't forgiven Matz
> > > for the whole, "0 is true" thing. ;-)
> > That is the single best feature of Ruby once you got used to it --
> > with "" is true!!!
>
> One of the biggest advantages to this is that it makes || and ||=
and one of its biggest dangers too, I wonder how much time has been
spent in looking for "Why has my already (with false) initialized
variable been overwritten?"
I am *not asking* that false evaluates to true, but I suggest that

x=false
x||=42
x --> false

or even
x ??= 42
for that semantics.

William James

unread,
Jul 18, 2007, 4:08:02 PM7/18/07
to
On Jul 16, 8:22 am, Raphael Gillett <r.gill...@rational.demon.co.uk>
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.

You're saying that it is self-evident that indexing
should start at 1. Remember the definition of "self-evident":

self-evident, adj. Evident to one's self and to nobody else.

Let's say you're programming in a low-level language.
If A is the address of an array, and S is the size
in bytes of an element, what's the address of the
Nth element?

If indexing is 0-based:
A + N*S

If indexing is 1-based:
A + (N-1)*S

Can you tell which is simpler?

Chad Perrin

unread,
Jul 18, 2007, 4:18:28 PM7/18/07
to
On Wed, Jul 18, 2007 at 08:54:36PM +0900, Robert Dober wrote:
> On 7/18/07, MenTaLguY <men...@rydia.net> wrote:
> >On Wed, 2007-07-18 at 16:20 +0900, kevin cline 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.
> >>
> >> With 50+ years of collective experience, it seems clear that zero-
> >> based arrays lead to the simplest code.
> >
> >That's been my personal experience, too -- pretty much the only thing
> >1-based indices make simpler is getting the last element of an array
> >given its size; everything else seems to get more complex.
> >
> I do not like categorical statements, but this one might be the
> exception that confirms the rule.
> +1 (or was that +0 ;)

Actually, that should probably be ++.

That brings up a good point, though. For rating systems and other needs
that work on similar principles, you're better off with zero-based
arrays.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Amazon.com interview candidate: "When C++ is your hammer, everything starts
to look like your thumb."

Chad Perrin

unread,
Jul 18, 2007, 4:23:48 PM7/18/07
to
On Thu, Jul 19, 2007 at 02:10:08AM +0900, John W. Kennedy wrote:
> kevin cline wrote:
> >On Jul 16, 8:22 am, Raphael Gillett <r.gill...@rational.demon.co.uk>
> >wrote:
> >>Ruby aims to be a human friendly programming language that embodies the
> >>principle of least surprise...
> >
> >>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.
> >
> >With 50+ years of collective experience, it seems clear that zero-
> >based arrays lead to the simplest code.
>
> ...unless there is a lot of exposure of nominal index values to the end
> user, in which case the additional effort of doing that may incur more
> complexity than is saved by using 0-origin internally.

Not always true. Think of voting systems, such as on reddit, where the
positive value of something is the sum of all the increment-votes and
decrement-votes assigned to it. The index value in a zero-based array
would be exactly what you'd want to expose to the end-user in such a
circumstance. Of course, such systems aren't always (or even usually,
perhaps) managed with an array -- but when you're trying to keep track of
who up- or down-voted something, as well as how many votes it got, an
array starts to look more interesting.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Dr. Ron Paul: "Liberty has meaning only if we still believe in it when
terrible things happen and a false government security blanket beckons."

dbl...@wobblini.net

unread,
Jul 18, 2007, 4:38:09 PM7/18/07
to
Hi --

On Thu, 19 Jul 2007, Robert Dober wrote:

> On 7/18/07, MenTaLguY <men...@rydia.net> wrote:
>> On Wed, 2007-07-18 at 22:56 +0900, Robert Dober wrote:
>> > > Lets not forget also that doing things for the sake of being different
>> help no
>> > > one. I for one must work in multiple languages. I still haven't
>> forgiven Matz
>> > > for the whole, "0 is true" thing. ;-)
>> > That is the single best feature of Ruby once you got used to it --
>> > with "" is true!!!
>>
>> One of the biggest advantages to this is that it makes || and ||=
> and one of its biggest dangers too, I wonder how much time has been
> spent in looking for "Why has my already (with false) initialized
> variable been overwritten?"
> I am *not asking* that false evaluates to true, but I suggest that
>
> x=false
> x||=42
> x --> false

But x ||= 1 is really: x = x || 1. So you'd end up with,
essentially, false || 1 being false, which wouldn't make sense, and
sort of would be false evaluating to true :-)


David

--
* Books:
RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
& consulting: Ruby Power and Light, LLC (http://www.rubypal.com)

Robert Dober

unread,
Jul 18, 2007, 4:53:02 PM7/18/07
to
On 7/18/07, dbl...@wobblini.net <dbl...@wobblini.net> wrote:
> Hi --
>
> On Thu, 19 Jul 2007, Robert Dober wrote:
>
> > On 7/18/07, MenTaLguY <men...@rydia.net> wrote:
> >> On Wed, 2007-07-18 at 22:56 +0900, Robert Dober wrote:
> >> > > Lets not forget also that doing things for the sake of being different
> >> help no
> >> > > one. I for one must work in multiple languages. I still haven't
> >> forgiven Matz
> >> > > for the whole, "0 is true" thing. ;-)
> >> > That is the single best feature of Ruby once you got used to it --
> >> > with "" is true!!!
> >>
> >> One of the biggest advantages to this is that it makes || and ||=
> > and one of its biggest dangers too, I wonder how much time has been
> > spent in looking for "Why has my already (with false) initialized
> > variable been overwritten?"
> > I am *not asking* that false evaluates to true, but I suggest that
> >
> > x=false
> > x||=42
> > x --> false
>
> But x ||= 1 is really: x = x || 1.
David I know that but it could be
x= 1 if x.nil?
Actually I think this might better reflect the common use cases, but
not be consistent (I said it again, sorry) with &&=, += etc, and that
probably would hurt too much.
And for that reason I was thinking about
x ??= 42.

That was the idea, sorry if I am not clear at all today :(

> So you'd end up with,
> essentially, false || 1 being false, which wouldn't make sense, and
> sort of would be false evaluating to true :-)

Why not, just kidding:)

John M. Gamble

unread,
Jul 18, 2007, 5:06:30 PM7/18/07
to
In article <69f66b790707161046p5c5...@mail.gmail.com>,
Tim Pease <tim....@gmail.com> wrote:
>On 7/16/07, ara.t.howard <ara.t....@gmail.com> wrote:
>>
>> On Jul 16, 2007, at 7:22 AM, Raphael Gillett wrote:
>>
>> > 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).
>>
>>
>> and we all know how 'natural' *those* languages are do program in
>> (ducks)...
>>
>
>Actually, if Ruby had been implemented in Fortran or Pascal, then most
>certainly arrays would have begun indexing with 1 instead of 0.

Well, if one were to blindly follow one's predecessors, yes - at least
with Fortran. Pascal lets you determine the array range, so you could
have the option of starting with zero. And indeed, when we first
encountered that possibility, zero got used a lot.

See, you are assuming that C worked some sort of mind control on poor
weak-willed programmers. Problem is, it isn't true. Being forced to
use 1 as the base index was actually a pain - the off-by-one problem
occurred much more often. And yes, I am old enough to have programmed
professionally in Fortran. There's a reason we don't use Fortran's
least-favored features anymore, no matter how good it was in numerical
programming, and it's not because of the tyranny of C.

Sorry, real life trumps dogma.

--
-john

February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.

Hal Fulton

unread,
Jul 18, 2007, 6:42:30 PM7/18/07
to
Raphael Gillett wrote:
>
> 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).
>

I sympathize, but if you were more experienced, I believe you would
understand it. Ruby does it the "right way."

No flames intended, but I am certain you are not from a computer science
background?


Hal


Michael P. Soulier

unread,
Jul 18, 2007, 7:02:38 PM7/18/07
to
On 19/07/07 John M. Gamble said:

> >Actually, if Ruby had been implemented in Fortran or Pascal, then most
> >certainly arrays would have begun indexing with 1 instead of 0.
>
> Well, if one were to blindly follow one's predecessors, yes - at least
> with Fortran. Pascal lets you determine the array range, so you could
> have the option of starting with zero. And indeed, when we first
> encountered that possibility, zero got used a lot.

I believe that Fortran also prevents recursion. Perhaps we should dump that
silly feature of Ruby too. ;-)

Joel VanderWerf

unread,
Jul 18, 2007, 9:11:06 PM7/18/07
to
Steven Lumos wrote:
> SonOfLilit <sonof...@gmail.com> writes:
>> I disagree. Zero based arrays are natural to a mathematician, and
>> programmers tend to be mathematicians.
>
> No! This is a systematic lie used to defend a convention that was
> adopted for purely practical reasons. It's like claiming that
> segmented memory is more natural to mathematicians. Mathematicians
> and even Computer Scientists consistently use 1, e.g.
>
> x_1, x_2, ..., x_n

If you're working in set theory, you get in the habit of 0 based
indexing, because then the index set is an ordinal number, i.e. ordinal
n = {0, ..., n-1}.

In other branches (esp. algebra), it has the advantage that you can
treat the indexes as a cyclic group, do modular arithmetic, etc.

In general, 0 based indexing makes it easier to make the leap from a
list of variables to a function with a natural domain.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

John W. Kennedy

unread,
Jul 18, 2007, 9:42:59 PM7/18/07
to
Michael P. Soulier wrote:
> On 19/07/07 John M. Gamble said:
>
>>> Actually, if Ruby had been implemented in Fortran or Pascal, then most
>>> certainly arrays would have begun indexing with 1 instead of 0.
>> Well, if one were to blindly follow one's predecessors, yes - at least
>> with Fortran. Pascal lets you determine the array range, so you could
>> have the option of starting with zero. And indeed, when we first
>> encountered that possibility, zero got used a lot.
>
> I believe that Fortran also prevents recursion. Perhaps we should dump that
> silly feature of Ruby too. ;-)

Historic FORTRAN was developed on hardware that made the use of arrays
in automatic story prohibitively expensive, so all historic FORTRAN
variables were static. Ergo, no recursion. But I know that automatic
variables came in in Fortran 77, and I'm pretty sure that recursion is
allowed now.

--
John W. Kennedy
"...if you had to fall in love with someone who was evil, I can see why
it was her."
-- "Alias"

M. Edward (Ed) Borasky

unread,
Jul 18, 2007, 10:44:40 PM7/18/07
to
Michael P. Soulier wrote:
> On 19/07/07 John M. Gamble said:
>
>>> Actually, if Ruby had been implemented in Fortran or Pascal, then most
>>> certainly arrays would have begun indexing with 1 instead of 0.
>> Well, if one were to blindly follow one's predecessors, yes - at least
>> with Fortran. Pascal lets you determine the array range, so you could
>> have the option of starting with zero. And indeed, when we first
>> encountered that possibility, zero got used a lot.
>
> I believe that Fortran also prevents recursion. Perhaps we should dump that
> silly feature of Ruby too. ;-)
>
> Mike

Well ... they *are* talking seriously about dumping Call/CC. How many
Ruby programmers, or, for that matter, C programmers, actually use
recursion, even tail recursion? Recursion has been mainstream in
programming languages since Algol 60, but how many people actually use
it outside of Lisp/Scheme and other functional languages?

Peter Seebach

unread,
Jul 18, 2007, 11:01:01 PM7/18/07
to
In message <469ED03E...@cesmail.net>, "M. Edward (Ed) Borasky" writes:
>Well ... they *are* talking seriously about dumping Call/CC. How many
>Ruby programmers, or, for that matter, C programmers, actually use
>recursion, even tail recursion? Recursion has been mainstream in
>programming languages since Algol 60, but how many people actually use
>it outside of Lisp/Scheme and other functional languages?

man qsort

-s

Chad Perrin

unread,
Jul 18, 2007, 11:03:11 PM7/18/07
to

Me, for one. It's not very common, but . . . once in a while, I do. Not
in Ruby yet, other than to play around, but in Perl a bit -- when it's
appropriate.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Marvin Minsky: "It's just incredible that a trillion-synapse computer could
actually spend Saturday afternoon watching a football game."

Chad Perrin

unread,
Jul 18, 2007, 11:11:25 PM7/18/07
to
On Thu, Jul 19, 2007 at 09:10:22AM +0900, Steven Lumos wrote:
> SonOfLilit <sonof...@gmail.com> writes:
> > I disagree. Zero based arrays are natural to a mathematician, and
> > programmers tend to be mathematicians.
>
> No! This is a systematic lie used to defend a convention that was
> adopted for purely practical reasons. It's like claiming that
> segmented memory is more natural to mathematicians. Mathematicians
> and even Computer Scientists consistently use 1, e.g.

Yes and no. I wouldn't call it "systematic", but it's certainly a
falsehood, even if propagated largely by accident or with innocent
misunderstanding. Excepting in the sense that one can regard computer
science as an alternate and self-contained mathematics, quite distinct
from the mainstream "mathematics" field of study, programmers are not so
universally mathematicians as so many people seem so convinced they are.

The fact that mathematicians these days tend to end up being programmers
does not translate to programmers tending to be mathematicians. This is
not a one-to-one correspondence.

As you say, the zero-based array is a practical matter related to the
work of programming (as well as being related to the applicability of set
theory to language design), and not a convenience for those wacky
mathematicians with their nonstandard way of counting (kind of a strange
claim to make). In contrast with your implication that this is somehow a
*bad* practical decision, however, it's actually the case that, by and
large, the benefits for natural sequential operations in programming and
the in-built compatibility of zero-based arrays with certain concepts of
set theory add up to a strikingly practical, and quite positive, reason
for zero-based arrays.

In other words, your premises are largely correct, but they do not lead
to the conclusions you seem to suggest.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

awj @reddit: "The terms never and always are never always true."

Phlip

unread,
Jul 18, 2007, 11:22:01 PM7/18/07
to
Joel VanderWerf wrote:

> If you're working in set theory, you get in the habit of 0 based indexing,
> because then the index set is an ordinal number, i.e. ordinal n = {0, ...,
> n-1}.
>
> In other branches (esp. algebra), it has the advantage that you can treat
> the indexes as a cyclic group, do modular arithmetic, etc.
>
> In general, 0 based indexing makes it easier to make the leap from a list
> of variables to a function with a natural domain.

Another way to say this is languages should lead programmers to think in
terms of set theory, not simplistic natural numbers, because the former is
much more sustainable.

Imagine a language that used 1-based indexing. It would make working in
0-based appallingly hard even for simple situations. So we would prefer this
slippery slope to slide in the correct direction.

--
Phlip
http://www.oreilly.com/catalog/9780596510657/
"Test Driven Ajax (on Rails)"
assert_xpath, assert_javascript, & assert_ajax


M. Edward (Ed) Borasky

unread,
Jul 19, 2007, 12:26:01 AM7/19/07
to
Chad Perrin wrote:
> Yes and no. I wouldn't call it "systematic", but it's certainly a
> falsehood, even if propagated largely by accident or with innocent
> misunderstanding. Excepting in the sense that one can regard computer
> science as an alternate and self-contained mathematics, quite distinct
> from the mainstream "mathematics" field of study, programmers are not so
> universally mathematicians as so many people seem so convinced they are.
>
> The fact that mathematicians these days tend to end up being programmers
> does not translate to programmers tending to be mathematicians. This is
> not a one-to-one correspondence.

In fact, there is a school of thought that says computer scientists
*shouldn't* be mathematicians! See

"Want to Be a Computer Scientist? Forget Maths" iTWire (07/05/07);
Corner, Stuart (http://www.itwire.com.au/content/view/13339/53/)

Of course, I think of myself as an applied mathematician, computer
scientist and software engineer as much as I think of myself as a
"programmer". I personally think the argument at the above link is a
steaming pile, in other words. :)


Sy Ali

unread,
Jul 19, 2007, 12:43:36 AM7/19/07
to
On 7/18/07, Phlip <phli...@yahoo.com> wrote:
> Imagine a language that used 1-based indexing. It would make working in
> 0-based appallingly hard even for simple situations. So we would prefer this
> slippery slope to slide in the correct direction.

I'm a very young programmer, and I've known about this 0 vs 1 issue
for a while now. Phlip's comment above is very good at explaining the
reason behind it, but I've had a hard time truly grasping it.

Is anyone willing to show some snippets of Ruby code which could
demonstrate the challenge of working with 1-based arrays? There were
some snippets in previous messages but they were too partial for me to
really understand things..

Chad Perrin

unread,
Jul 19, 2007, 1:03:40 AM7/19/07
to

> irb
irb(main):001:0> foo = %w[zero one two three]
=> ["zero", "one", "two", "three"]
irb(main):002:0> puts "last element: #{foo[-1]}"
last element: three
=> nil

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

John Kenneth Galbraith: "If all else fails, immortality can always be
assured through spectacular error."

Michael Ulm

unread,
Jul 19, 2007, 4:17:07 AM7/19/07
to
Steven Lumos wrote:
> SonOfLilit <sonof...@gmail.com> writes:
>> I disagree. Zero based arrays are natural to a mathematician, and
>> programmers tend to be mathematicians.
>
> No! This is a systematic lie used to defend a convention that was
> adopted for purely practical reasons. It's like claiming that
> segmented memory is more natural to mathematicians. Mathematicians
> and even Computer Scientists consistently use 1, e.g.
>
> x_1, x_2, ..., x_n
>

I've worked for over 10 years as a mathematician on a university
level. I've met and worked with mathematicians from all continents
except Antarctica and from more nations that I care to count.
So, I think I speak with some authority when I say, that there is a
definitive consensus amongst a vast majority of mathematicians
concerning this issue, and this is that they don't care all that
much.

For a mathematician, the start of a sequence isn't that interesting
anyway. They much more care about the other end at infinity.
Personally, when doing mathematics my sequences start with x_0,
unless they don't.

Regards,

Michael


--
Michael Ulm
R&D Team
ISIS Information Systems Austria
tel: +43 2236 27551-542, fax: +43 2236 21081
e-mail: micha...@isis-papyrus.com
Visit our Website: www.isis-papyrus.com

---------------------------------------------------------------
This e-mail is only intended for the recipient and not legally
binding. Unauthorised use, publication, reproduction or
disclosure of the content of this e-mail is not permitted.
This email has been checked for known viruses, but ISIS accepts
no responsibility for malicious or inappropriate content.
---------------------------------------------------------------

Adrian Howard

unread,
Jul 19, 2007, 5:04:36 AM7/19/07
to

On 19 Jul 2007, at 09:58, Adrian Howard wrote:

> (taken off-list since wandering way OT :-)
[snip]

Or it would have been if I'd had more coffee this morning - sigh -
apologies all.

Adrian

Adrian Howard

unread,
Jul 19, 2007, 5:13:56 AM7/19/07
to
(taken off-list since wandering way OT :-)

On 17 Jul 2007, at 20:03, Chad Perrin wrote:

> On Tue, Jul 17, 2007 at 10:43:35PM +0900, Adrian Howard wrote:
>>
>> 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" :-)
>
> News to me. Would you point me at more information on the topic,
> please?

In the perl world we have the $[ variable (see perldoc perlvar for
gory details) that resets the index of the first element. As the
documentation says "Its use is highly discouraged.". I'd imagine that
it's primary motivation for inclusion was to make compatability with
awk easier in early perl's (which also has 1 indexing).

For example:

my @array = ( 1 .. 10 );

$[ = 0;
print @array[5], "\n";

$[ = 1;
print @array[5], "\n";

$[ = 2;
print @array[5], "\n";

would produce

6
5
4

Spooky action at a distance. Scary.

Fortran (or those versions that support it anyway) allow you to
specify the indices of a particular array - so for example you could
have

real temperature(-100:100)

to make an array of real values with indices from -100 to 100. So you
can make the indices of your array match the indices of your domain -
if that would make your life easier :-)

See <http://www.stanford.edu/class/me200c/tutorial_77/10_arrays.html>
for some examples.

Cheers,

Adrian

Robert Dober

unread,
Jul 19, 2007, 5:50:51 AM7/19/07
to
There is no indication of recursion in the man page.

But I have nothing against recursion.

Robert
>
> -s

M. Edward (Ed) Borasky

unread,
Jul 19, 2007, 10:04:05 AM7/19/07
to
Logan Capaldo wrote:

> You've never written code to traverse some kind of tree? And if you have,
> you did it all iteratively? I would suggest _lots_ of programmers use
> recursion, even in C.

There's a big difference between an explicit stack with iterative code
and recursion with an implicit stack. I've done a lot of explicit stack
coding for walking data structures -- indeed, the last time I did so was
a recent piece of code that generates the state space of a large finite
Markov chain. But the only time I've written recursive functions as a
*preferred* modus operandi has been in Lisp, Scheme and the Lisp-based
symbolic math package Derive. And there, I've always aimed for tail
recursion.
>


Robert Dober

unread,
Jul 19, 2007, 10:23:43 AM7/19/07
to
I see recursion as a useful tool of abstraction I remember having
implemented quick sort on a Sharp PC [forgot the name] in its
primitive Basic dialect. There were 13 cells left to be sorted LOL.
Never ever has a program given me more satisfaction, but nowadays I
would rather not waste my time on doing it manually, well I remember a
fascinating post of James explaining that unwinding the stack has
become second nature to him.
But who else will be able and/or willing to read your program?

Just my 2 nickels.

R.

Chad Perrin

unread,
Jul 19, 2007, 11:17:47 AM7/19/07
to
On Thu, Jul 19, 2007 at 06:13:56PM +0900, Adrian Howard wrote:
> (taken off-list since wandering way OT :-)

Understandable.


>
> On 17 Jul 2007, at 20:03, Chad Perrin wrote:
>
> >On Tue, Jul 17, 2007 at 10:43:35PM +0900, Adrian Howard wrote:
> >>
> >>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" :-)
> >
> >News to me. Would you point me at more information on the topic,
> >please?
>
> In the perl world we have the $[ variable (see perldoc perlvar for
> gory details) that resets the index of the first element. As the
> documentation says "Its use is highly discouraged.". I'd imagine that
> it's primary motivation for inclusion was to make compatability with
> awk easier in early perl's (which also has 1 indexing).

I didn't know about the likely awk connection in the existence of $[, and
didn't know early Perl used 1-indexing. I guess I learn something new
every day.

When I said something was news to me, however, I meant specifically your
statement that the "fix" was global rather than per-array. I somehow
read that as "it applies globally, and you can't make it apply per
array", rather than how I now realize you meant it. When you first
mentioned that, I thought you were saying there was something like
perhaps a pragma that changed the way Perl handled arrays, or something
like that.

. . but yeah, I see now you were just referring to the fact that $[ is
a global variable. Of course, there's always the local hack:

{
local $[ = 1;
# do stuff
}

>
> For example:
>
> my @array = ( 1 .. 10 );
>
> $[ = 0;
> print @array[5], "\n";
>
> $[ = 1;
> print @array[5], "\n";
>
> $[ = 2;
> print @array[5], "\n";
>
> would produce
>
> 6
> 5
> 4
>
> Spooky action at a distance. Scary.

A little weird, to be sure -- but awfully flexible if you need it, I
suppose. Probably the most disturbing thing about it for me is the fact
that, for each of the changes to $[ in your code snippet, that changes
the behavior of *all* arrays. Downright terrifying.


>
> Fortran (or those versions that support it anyway) allow you to
> specify the indices of a particular array - so for example you could
> have
>
> real temperature(-100:100)
>
> to make an array of real values with indices from -100 to 100. So you
> can make the indices of your array match the indices of your domain -
> if that would make your life easier :-)

I don't know any Fortran, so the talk of Fortran and arbitrary array
ranges is entirely new to me -- and fascinating. The various differences
of feature sets between languages really teaches some interesting
principles, I find.

Thanks.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Chad Perrin

unread,
Jul 19, 2007, 11:18:58 AM7/19/07
to

. . and I replied without checking the address. Heh. I guess I helped
propagate the mistake. Ouch.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

John Joyce

unread,
Jul 19, 2007, 3:36:35 PM7/19/07
to

On Jul 19, 2007, at 2:19 PM, Steven Lumos wrote:

> "Wayne E. Seguin" <waynee...@gmail.com> writes:


>> On Jul 18, 2007, at 20:10 , Steven Lumos wrote:
>>> No! This is a systematic lie used to defend a convention that was
>>> adopted for purely practical reasons. It's like claiming that
>>> segmented memory is more natural to mathematicians. Mathematicians
>>> and even Computer Scientists consistently use 1, e.g.

>>> <snip>
>>
>> I am a (US) Mathematician as are several of my close friends and we
>> all use 0 based indexing almost exclusively in our Mathematics work.
>> That said I do have to admit we all deal mainly in various branches
>> of Mathematical Logic.
>
> I stand by my claim in spite of a pair of anecdotal reports. Don't
> make me survey your papers. :-) (Actually, I can't find many, if any,
> publications for either of you. I'm not saying that means anything.)
>
> Steve
>
> P.S. If this is you then I suspect we may have mutual acquaintances:
> http://www.google.com/patents?hl=en&lr=&vid=USPAT5885158
>
>
This whole business about 1 or 0 based indexing is not important.
It's a moot point.
If you want it added to the language, ask at Ruby Core, Matz does
read this stuff and does care what users think.
But if it doesn't change, don't waste time or electrons complaining
and arguing about it.
I'd like a lot of languages to change (CSS is one) but if you really
want it, make it.
That's what Matz did!
Larry Wall made Perl, Guido Van Rossum made Python, and that guy who
made PHP.
Many of the more advanced, more esoteric languages were started as
the efforts of a single person.


Chad Perrin

unread,
Jul 19, 2007, 6:31:13 PM7/19/07
to
On Fri, Jul 20, 2007 at 03:46:11AM +0900, Steven Lumos wrote:
> Chad Perrin <per...@apotheon.com> writes:
> >
> > As you say, the zero-based array is a practical matter related to the
> > work of programming (as well as being related to the applicability of set
> > theory to language design), and not a convenience for those wacky
> > mathematicians with their nonstandard way of counting (kind of a strange
> > claim to make). In contrast with your implication that this is somehow a
> > *bad* practical decision, however, it's actually the case that, by and
> > large, the benefits for natural sequential operations in programming and
> > the in-built compatibility of zero-based arrays with certain concepts of
> > set theory add up to a strikingly practical, and quite positive, reason
> > for zero-based arrays.
>
> Not only did I not mean to imply that, but I'm not sure I can even
> parse "bad practical decision". If I knew the evidence I had implied
> in support of my implied claim then maybe I could. :-)
>
> But I even explicitly said that "It's a good and safe decision
> supported by decades of computing convention and habit..."

That would be why I used terms like "seem" and so on in that email -- I
wasn't 100% certain of your intent, based on what you said.


>
> > In other words, your premises are largely correct, but they do not lead
> > to the conclusions you seem to suggest.
>

> I'm just sick of hearing that Ruby does such and such because
> mathematicians like it.

Fair enough. I agree with you on that score, actually -- that it gets
kind of old seeing people try to equate everything in computer science
with the will of mathematicians. That's the sort of thinking that leads
to CS students wasting time on trigonometry when they could be spending
it on something useful to computer science, like linear algebra.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Larry Wall: "A script is what you give the actors. A program is what you
give the audience."

Ken Bloom

unread,
Jul 19, 2007, 8:08:45 PM7/19/07
to
On Mon, 16 Jul 2007 22:22:05 +0900, Raphael Gillett wrote:

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

If you were going to argue for arbitrarily indexed arrays e.g. those
ranging from 47 thru 300 or from -26 thru 68, you might have a point that
there's something more natural in your proposal. (Although it would break
other features of arrays that we hold very dear to our hearts.)

Arguing 1-based arrays to replace 0-based arrays is arbitrary at best,
and unnatural at worst.

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/

John W. Kennedy

unread,
Jul 19, 2007, 8:45:51 PM7/19/07
to
M. Edward (Ed) Borasky wrote:

I used it just the other day in a Ruby solver for
<URL:http://xkcd.com/c287.html> (I should add that the last time I even
/thought/ about a packing problem was 1967, so my approach was brute force.)

--
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood/index.html

Robert Dober

unread,
Jul 20, 2007, 8:17:47 AM7/20/07
to
On 7/20/07, Logan Capaldo <loganc...@gmail.com> wrote:
> On 7/19/07, M. Edward (Ed) Borasky <zn...@cesmail.net> wrote:
> >
> Interesting. This is wild speculation of course, but I imagine you are
> probably atypical as far as always using explicit stacks. (Since I get the
> impression from your post history that you are heavily focused on
> performance.). I would guess (more speculation ;)) that if someone were to
> grab a set of programs that for instance walked an XML DOM (or a similar day
> to day tree structure, like a nested directory) that the vast majority of
> those programs would use recursion with implicit stacks. Now that I've
> contributed that bit of unsubstantiated nonsense, I'll resume eating my
> dinner. :)
>
I remember a funny use case of explicit stack handling now.
About 4 years ago I was writing an XML wrapper around the Python tupleparser.
I started recursively, of course and very soon got completely lost, I
tried to undo the recursion so that I had full control over some
details on the call stack (things like cheating by examining the call
stack) never got anywhere but I have to admit it was good to have that
technique at my disposal.
If I recall correctly I would probably have used a recursive approach
with yield in Ruby...

But I agree these are rare exceptions and no reason at all not to use
recursion, a better design might have allowed for a recursive solution
too :)

Cheers
Robert

Ken Bloom

unread,
Jul 20, 2007, 12:08:07 PM7/20/07
to
On Wed, 18 Jul 2007 22:45:34 +0900, Michael P. Soulier wrote:

> On 18/07/07 Robert Dober said:
>
>> I do not like categorical statements, but this one might be the
>> exception that confirms the rule.
>> +1 (or was that +0 ;)
>
> Lets not forget also that doing things for the sake of being different
> help no one. I for one must work in multiple languages. I still haven't
> forgiven Matz for the whole, "0 is true" thing. ;-)

But in the shell, zero is the ONLY return code which is true.

--Ken

M. Edward (Ed) Borasky

unread,
Jul 21, 2007, 12:11:30 AM7/21/07
to
Well ... maybe "Computer Science" students don't need to know
trigonometry, but I doubt very seriously a trig-impaired person could
get an Electrical Engineering degree. Hell, if they didn't have trig and
calculus and analytic geometry under their belts on the SAT, they
couldn't get *into* a EE program!

I was actually one of the first students in the USA to get calculus and
analytic geometry in high school. This was right after Sputnik and I
lived in a town full of scientists and engineers. I was also fortunate
to have graduated before the "New Math", which was mostly set theory.

So ... would you say queuing theory is useful to computer science? I
certainly would. Well, it turns out, as we mathematicians like to say,
that you can use a Fast Fourier Transform to solve some queuing theory
problems that are more or less intractable otherwise. Can you do a Fast
Fourier Transform without sines and cosines?

M. Edward (Ed) Borasky

unread,
Jul 21, 2007, 12:23:15 AM7/21/07
to
Logan Capaldo wrote:
> Interesting. This is wild speculation of course, but I imagine you are
> probably atypical as far as always using explicit stacks. (Since I get the
> impression from your post history that you are heavily focused on
> performance.). I would guess (more speculation ;)) that if someone were to
> grab a set of programs that for instance walked an XML DOM (or a similar
> day to day tree structure, like a nested directory) that the vast majority of
> those programs would use recursion with implicit stacks. Now that I've
> contributed that bit of unsubstantiated nonsense, I'll resume eating my
> dinner. :)

1. I am the very model of premature optimization. Unless the underlying
run-time has made a great effort to make (tail) recursion efficient,
like most Lisps, Schemes, and the core of Derive, it's usually less
efficient than iteration and harder for other programmers to understand.

2. I've been quite fortunate in avoiding XML so far. I like *my* trees
with squirrels and blue jays in them, thankyouverymuch.

3. Perhaps Charles Nutter would comment on how efficient jRuby on the
JVM is at recursive code compared to MRI Ruby. I'd expect it to be
better, given that some Schemers were involved in the creation of Java. :)
>


Chad Perrin

unread,
Jul 21, 2007, 1:50:42 AM7/21/07
to

There's a pretty big difference between "electrical engineering" and
"computer science".


>
> I was actually one of the first students in the USA to get calculus and
> analytic geometry in high school. This was right after Sputnik and I
> lived in a town full of scientists and engineers. I was also fortunate
> to have graduated before the "New Math", which was mostly set theory.
>
> So ... would you say queuing theory is useful to computer science? I
> certainly would. Well, it turns out, as we mathematicians like to say,
> that you can use a Fast Fourier Transform to solve some queuing theory
> problems that are more or less intractable otherwise. Can you do a Fast
> Fourier Transform without sines and cosines?

Maybe not -- but my objection is more to the saddling of CS students with
several years of trig and calculus *classes* than with the imparting of
any of the basics that are related to those subjects. The basics of
trigonometry as taught in a trig class, in fact, can be imparted to a
student quite thoroughly in about two class sessions -- and it usually
is, in a preceding geometry or algebra course. Meanwhile, the rest of
what's "taught" in typical college trig courses can be easily derived
from the basics, and is just rote memorization for the purpose of passing
tests, to be forgotten immediately after the test in time to memorize for
the next exam.

Meh. I have traumatic experiences of almost being entirely turned off of
"higher education" by the stupidities of a computer science curriculum.
Your mileage may vary.

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]

Baltasar Gracian: "A wise man gets more from his enemies than a fool from
his friends."

Wayne E. Seguin

unread,
Jul 30, 2007, 2:21:00 PM7/30/07
to

On Jul 19, 3:19 pm, Steven Lumos <ste...@lumos.us> wrote:
> I stand by my claim in spite of a pair of anecdotal reports. Don't
> make me survey your papers. :-) (Actually, I can't find many, if any,
> publications for either of you. I'm not saying that means anything.)

http://en.wikipedia.org/wiki/Mathematician

Kaldrenon

unread,
Jul 31, 2007, 12:29:22 PM7/31/07
to
On Jul 18, 10:44 pm, "M. Edward (Ed) Borasky" <zn...@cesmail.net>
wrote:

> Well ... they *are* talking seriously about dumping Call/CC. How many
> Ruby programmers, or, for that matter, C programmers, actually use
> recursion, even tail recursion? Recursion has been mainstream in
> programming languages since Algol 60, but how many people actually use
> it outside of Lisp/Scheme and other functional languages?

I haven't had /that many/ opportunities to use recursion, but I tend
to use it wherever it is both applicable and not prohibitively
resource intensive. The latter is a valid concern when choosing how to
solve a given problem, but for cases in which recursion won't blow the
stack or drastically affect performance, I like to use it. Not because
it's /better/, per se...just because it's more fun and often a bit
more challenging.

Granted, I'm still a student in the early part of my education, so I
don't know how viable recursion will be for me in "the real world", in
consumer apps and the like, but I'll still use it when I see an
opportunity.

0 new messages