In message
[email protected], “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
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.
On 7/16/07, Raphael G. [email protected] 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.
Peter S. wrote:
-s
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.
Here [0] a link to Dijkstra arguing why numbering should start at zero.
Regards,
Felix
[0] -
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
Agreed.
The pebble is a ruby
Sent from my iPhone
On Jul 17, 2007, at 12:00 AM, Peña, Botp [email protected]
Don’t feed the trolls.
Religion, wannabe game programmers, and now this! The list is driving me
nuts this past week.
Pete Y.
From: Raphael G. [mailto:[email protected]]
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
On 7/16/07, Martin DeMello [email protected] wrote:
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
On 16/07/07, Raphael G. [email protected] wrote:
suit the compiler/interpreter at the expense of the person.
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
- 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.
On 7/17/07, Frank C. [email protected] wrote:
Java. In violation of Ruby’s ethos, this feature is present purely to
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
- 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
On 7/17/07, Frank C. [email protected] wrote:
Chinese count birthdays starting with the child’s first year as year
- 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.
It depends how you look at arrays. If you think of each element as,
well…
an “element” then the argument for 1 based arrays is supported by how
things
work in real life. For example, you would consider the first year of a
child’s existence to be “year 1”. Year 1 is “the year” (that is, the
“element”) between birth and the age of 1.
If you split things into boxes, which, arguably, is what an array is,
then
starting from 1 actually makes sense. A line of boxes is not inherently
0-based. You have boxes 1, 2, 3, and so forth… but no-one says the
first
element of a collection of natural items is “item 0.”
I don’t see the original post as a troll at all other than in its
implication that Ruby is a “human friendly” programming language. It
might
be “human friendly” but that human is a computer programmer… If Ruby
was
meant to be novice friendly, then sure, 1-based indexing makes sense. Of
course, I quite like 0-based indexing, though I recognize it doesn’t
really
make much sense in layman’s terms… but most of computer science
doesn’t.
Cheers,
Peter C.
http://www.petercooper.co.uk/
On 7/17/07, rio4ruby [email protected] 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
Raphael G. 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.
On 16 Jul 2007, at 19:22, Lloyd L. wrote:
Tim P. 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
On Jul 16, 4:57 pm, “Robert Parker” [email protected] wrote:
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.
As a former bartender, I take umbrage at this remark. We all used zero
based indexing.
On 7/17/07, Adrian H. [email protected] wrote:
On 16 Jul 2007, at 19:22, Lloyd L. wrote:
Tim P. 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[] of ;
It was up to you, right? Maybe you are talking of some dialects or did
I really forget??
[snip]
On 17 Jul 2007, at 14:27, James Edward G. II wrote:
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
On Jul 17, 8:27 am, James Edward G. II [email protected]
wrote:
breaks way too much. I’m pretty sure it’s being removed in Perl 6.
James Edward G. 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.
–
-yossef
Adrian H. 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.
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.