Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is not more intuitive.

It just matches the convention used in the language that one has learned as a child, so one is already familiar with it.

The association between ordinal numbers and cardinal numbers such that "first" corresponds to "one" has its origin in the custom of counting by uttering the string "one, two, three ..." while pointing in turn to each object of the sequence of objects that are counted.

A more rigorous way of counting is to point with the hand not to an object, but to the space between 2 successive objects, when it becomes more clear that the number that is spoken is the number of objects located on one side of the hand.

In this case, it becomes more obvious that the ordinal position of an object can be identified either by the number spoken when the counting hand was positioned at its right or by the number spoken when the counting hand was positioned at its left, i.e. either "0" or "1" may be chosen to correspond to "first".

Both choices are valid and they are mostly equivalent, similarly to the choice between little-endian and big-endian number representation. Nevertheles, exactly like little-endian has a few advantages for some operations, so eventually it has mostly replaced big-endian representations, the choice of "0" for "first" has a few advantages and it is good that it has mostly replaced the "1 is first" convention.

For people who use only high-level programming languages, the differences between "0 is first" and "1 is first" are less visible, exactly like the differences between little-endian and big-endian. In both cases the differences are much more apparent for compiler writers or hardware implementers.

Besides "1 is first" vs. "0 is first" and little-endian vs. big-endian, there exists another similar choice, how to map the locations in a multi-dimensional array to memory addresses. There is the C array order and the Fortran array order (where elements of the same column are at successive addresses).

Exactly like "1 is first" and big-endian numbers match the conventions used in writing the European languages, the C array order also matches the convention used in the traditional printed mathematical literature.

However, exactly like in the other 2 cases, the opposite convention to the traditional written texts, i.e. the Fortran array order is the superior convention from the point-of-view of the implementation efficiency. Unfortunately, because much less people are familiar with the implementation of linear algebra than with the simpler operations with numbers and uni-dimensional arrays or strings, so they are not aware about the advantages and disadvantages of each choice, the Fortran array order is used only in a minority of programming languages. (An example of why the Fortran order is better is the matrix-vector product, which must never be implemented with scalar products as misleadingly defined in textbooks, but with AXPY operations, which are done with sequential memory accesses when the Fortran order is used, but which require strided memory accesses if the C order is used. There are workarounds when the C order is used, but with the Fortran order it is always simpler.)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: