why arrays start at zero?

  1. 2 months ago

    nicolás c

    Aug 11 Pre-Release Testers, Xojo Pro argentina

    that's all... why arrays start at zero? I think it would be more practical to start with one. I do not mean just to xojo... In most languages it happens that way

    link 1 [or zero :-)]--> http://developeronline.blogspot.com.ar/2008/04/why-array-index-should-start-from-0.html

    link 2 --> http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF

    link 3 --> http://dexarg.com/index.php?option=com_content&view=article&id=68&catid=22&Itemid=494&lang=es

    Information in Spanish extracted from the previous link--> Esta es la respuesta de Edsger Dijkstra publicada en Hacker News y que fue enviada como una carta personal del famoso programador a un colega en 1982. La primera respuesta de Dijkstra dice que para denotar una secuencia de números naturales es mejor una notación 0 < i < N, que una 1 <= i < N+1. Habla también de experiencias donde una notación que empieza en 1 lleva a errores al leerla y no determinar bien los límites inferiores/superiores que se quieren denotar--> I think this is a great explanation

    i think this is a great explanation too (@Sascha Schneppmueller)--> I assume it's because the index of an array is pointing to an offset within your systems memory

  2. Sascha S

    Aug 11 Pre-Release Testers, Xojo Pro Germany/W'haven
    Edited 2 months ago by Sascha S

    I assume it's because the index of an array is pointing to an offset within your systems memory.

    Found this: http://developeronline.blogspot.de/2008/04/why-array-index-should-start-from-0.html

  3. Mark C

    Aug 11 Pre-Release Testers, Xojo Pro Spain 35510

    if you wish to start the address at 1 then all you have to do is make the array 1 larger than you need and just ignore array(0) totally and never use it.

  4. Emile S

    Aug 11 Europe (France, Strasbourg)

    This question recalls me a kid question: “from where the wind comes ?”

    Nicólas:
    With time, as a developer, you will discover you always have to check if the object is 0-based or 1-based.

    Of course as a user, you do not care since it always start at 1.

  5. Markus W

    Aug 11 #JeSuisHuman Europe (Germany)...
    Edited 2 months ago by Markus W

    Historical reasons. And array position zero was often used for other purposes. But no, "most" other languages do NOT start at 1.

    For more info see http://developeronline.blogspot.de/2008/04/why-array-index-should-start-from-0.html

    P.S. Oops, Sascha beat me to it.

  6. Roger C

    Aug 11 Lewis Center, OH

    if you wish to start the address at 1 then all you have to do is make the array 1 larger than you need and just ignore array(0) totally and never use it.

    = recipe for disastrous coding. Way, way back I used to do this. Future Basic (remember that?) had an option to start arrays at 1. Caused me untold headaches.

  7. nicolás c

    Aug 11 Pre-Release Testers, Xojo Pro argentina
    Edited 2 months ago by nicolás c

    I really liked this explanation (http://developeronline.blogspot.com.ar/2008/04/why-array-index-should-start-from-0.html)...

    The discussion over why the array index should start at zero is not a trivial one and relates to interesting concepts from computer science. First of all, it has strong relation to language design. For example in C, the name of an array is essentially a pointer, a reference to a memory location, and so the expression array[n] refers to a memory location n-elements away from the starting element. This means that the index is used as an offset. The first element of the array is exactly contained in the memory location that array refers (0 elements away), so it should be denoted as array[0]. Most programming languages have been designed this way, so indexing from 0 is pretty much inherent to the language.

    Your comments have been great and enlightening

  8. nicolás c

    Aug 11 Pre-Release Testers, Xojo Pro Answer argentina

    link 1 [or zero :-)]--> http://developeronline.blogspot.com.ar/2008/04/why-array-index-should-start-from-0.html

    link 2 --> http://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF

    link 3 --> http://dexarg.com/index.php?option=com_content&view=article&id=68&catid=22&Itemid=494&lang=es

    Information in Spanish extracted from the previous link--> Esta es la respuesta de Edsger Dijkstra publicada en Hacker News y que fue enviada como una carta personal del famoso programador a un colega en 1982. La primera respuesta de Dijkstra dice que para denotar una secuencia de números naturales es mejor una notación 0 < i < N, que una 1 <= i < N+1. Habla también de experiencias donde una notación que empieza en 1 lleva a errores al leerla y no determinar bien los límites inferiores/superiores que se quieren denotar--> I think this is a great explanation

    i think this is a great explanation too (@Sascha Schneppmueller)--> I assume it's because the index of an array is pointing to an offset within your systems memory

  9. Starting an array at "0" comes from old times when computer memory was very small. At that time, starting at "1" means a waste of valueble memory space.

    I created applications where I had less than 5 KB for the application itself and its data in RAM.

    Nowadays developers are spoiled.

or Sign Up to reply!