On 4/13/2012 9:07 AM, Leif Roar Moldskred wrote:

> You'll never see a mathematican refer to the 0th element of an array

> or vector. Zero-based arrays most certainly are an idiosyncrasy of

> programming languages -- which sometimes, such as for C, makes

> sense. For a programming language that does arrays right, look to Ada.
I see lots of references to things like x_0 in mathematics. It really

comes down to "is 0 the first natural number or is 1 the first natural

number?" Edgar Dijkstra (I believe) once laid out his opinion of array

indexing and arrived at the conclusion that 0 <= i < n is the most

natural way to do for-loop-iteration, so array indexing should start at

0 and not 1. The argumentation, IIRC, boils down roughly as follows:

1. [start, start + length) is the most natural bound

2. Length should be a simple expression, i.e., n

3. Using (<=, <) as your pair of comparison most clearly indicates the

use of [a, b) notation

4. Thus, start <= i < start + n is the appropriate notation.

5. When the start is the beginning of the array, start + n should just be n

6. So start should be 0, and we get 0 <= i < n

There are occasionally places where 1-based indexing makes more sense

(array-based heap notations are a particularly well-known example), but

I'm not sure that giving programmers the ability to choose array bounds

is the best option.

Also, FWIW, the convention of 1 being the "first" number isn't totally

universal: the Mayans started from 0. And they were arguably the best

mathematicians of their time.

>> I don't believe it is reasonable to accuse any programming language of being

>> "too crufty to make for a good introductory language" if the only problem

>> which has been pointed out boils down to ignorance regarding how to use that

>> programming language. No programming language, no matter how appropriate it

>> might be as an introductory language, enables you to write any code without

>> first learning how to do it.
So we should start by teaching everyone APL, right?

The problem is that discussing a basic Hello World in Java requires, at

a minimum, handwaving the public class HelloWorld, the public static

void main, System.out.println, and the entire compilation procedure. If

you don't handwave, you have to give a lengthy amount of time to

explaining how object-oriented programming works before you can begin

discussing programming. You also very quickly get to bugaboos with

explicit typing, doing I/O (reading from stdin is surprisingly

complicated in Java), collections (generics is complicated enough for

seasoned programmers; for those just starting a few weeks ago, it's an

imposing cliff).

--

Beware of bugs in the above code; I have only proved it correct, not

tried it. -- Donald E. Knuth