29
Milt0n
6y

At University we are currently learning why we should use 1-based Arrays not 0-based.

Comments
  • 1
  • 3
  • 4
    So what are they telling you?
  • 0
    Lua doesn't have arrays tho
  • 3
    OK, why should we? What are the arguments?
  • 2
    I'm also curious what the arguments are in your university.
    As this is the 0th time I've heard something like this.
  • 2
    @kenogo I guess arrays start with 0 because that is the default value assigned to `int` in most languages. ( I might be wrong ).
    Maybe it has to be that the first default memory address is 0x0 and it made sense back then to start arrays by 0 ( and I don't know wtf I'm talking about )

    It actually makes sense, to me, to start counting from 0 , everybody learns the sequence of numbers is:

    0 , 1, 2 , 3...

    Anyway, what confuses people (at least me) about array indexing are functions like:

    `getArraySlice(countsFromOne, countsFromZero)`

    These kind of function make me wanna scream and murder the dev, and a lot of languages do this shit.
  • 1
    @zlice nothing starts from nothing.
  • 1
    @kenogo yeah, that is the behaviour of most array transformations but wouldn't it be a lot more intuitive if it was:

    arr = [8,6,3,5,1]
    get_art_slice(arr,1,3)
    > [6,3,5]

    I was always confused by that.
    It is as @SoulSkrix said, the offset, but why can't it be "slice by index, inclusive" ?
    Because most of those function mix offset with index.
  • 0
    @azous are you saying that “nothing COMES from nothing” or are you saying that “NOTHING comes from nothing”? It could be interpreted both ways.
  • 1
    @epetrov I said that:
    "A thing" to exist there must be previous existence that promoted its existence.

    But you might argue: but dude, some "day" there has to be a time where there was no things, no atoms, no electromagnetic forces, no "things" and out of nowhere there was the first "thing" and the second "thing" and so on.

    Yeah, logically there was a time where "things" came to existence out of no "things" but to maintain sanity:
    Nothing comes from nothing.
  • 1
    @SoulSkrix yeah, I always panic 😂
  • 0
    I think it should have been implemented starting at 1 from the very beginning, as this is how we count. However, now that it's basically established law, some individual languages starting from 1 are just making the confusion worse.
Add Comment