Why in the ever living fuck is 0 an accessible array index?
Why in the ever living fuck is 0 an accessible array index?
fuck off retard
The array index indicates the offset in memory
>why in the fuck does the number line start at 0
Brainlet
Because your mum dropped you
This, first element has offset 0.
Yes OP, it's retard shit taken from old languages like C. Many languages start indexing at 1 (which is logical).
>which is logical
HAHAHAHAHAHAHAHA look at this fucking retard!
But..but.. we all count from 1, not 0.
BAITEDDDDDDDDDDD xDDDDDDDDDDDDDDDDDDDDDDD
Computers don't
got me you were only pretending to be retarded should have known
>that boomer who doesn't consider 0 a natural number.
he was being facetious
humans count from 0 too, every number is just an offset left or right from 0 on the number line
>that newfag who thinks boomer is a cool meme
you're such a fucking boomer
Pretty much this
cs.utexas.edu
your intellect level is less than its of a bee
[Numerical ordering of zero in honey bees] science.sciencemag.org
Read this, OP. Dijkstra is smarter than you and I.
IMO list indexing should start at 0 in lower-level languages which are aware of array pointers, 1 everywhere else. 1 is natural for lists since you start iterating items 1, 2, ... It's about using the most fitting range for the task, and for lists it's 1..n. For something else it might be 0-based. 1 also works painlessly excluding the few odd times you'll maybe need to do an extra -1.
And the first item of an array is offset 1 from zero.
Surprisingly weak argument from Dijkstra
Is he talking about array indexing or range intervals? Because I consider those different things.
Did you even understand it? Admittedly, it's a bit too advanced for monkeys to understand.
if you start with 1, then the lower and upper bound for an empty list is 1, 1 instead of the more intuitive 0, 0.
Zero is the most natural of the natural numbers, kid.
>matlab
>lua
have fun with these two, leave us real programmers alone
computers don't
Simple question.
Doctor give you prescription to take 3 pills, but you need to make 1h30 pause between each one.
How long will it take for you to consume all.
If you take one now (which is counting from zero) it will take 3h.
Got it? There is no sense to wait 1h30m now before taking 1st pill.
lol
maybe if your arrays are defines that way
I like starting from 1 but being able to set the bounds when you allocate the array is even better
e.g you could make the array go (-10:10) if you so desired.
inclusive-exclusive indexing is fucking aids though
Cause 0 is important to machines? You know 0's and 1' not 1's and 2's
Another thing I like to point out is natural numbers.
In decimal you have ten symbols from set {0,1,2,3,4,5,6,7,8,9}. Meaning that 0 itself is "commonly" a first element from iterating through natural (discrete) set.
yeah but now 9 is the 10th element
9 is the 10th number in base 10 :)
You need to learn the difference between the countability of set (power of set) and actual value.
The idea of going through array is to iterate through the mathemtical set.
Thanks, I forgot about base.
Other example, base 2 has set {0,1}. It has 2 elements.
Base 16 has from 0 to F (decimal 15). It has 16 elemets.
>and actual value.
this is fine and all if your actual value is arbitrary, but sometimes your code would be cleaner if you could define the array bounds yourself such that the indices coincide with the values
only the most patrician of languages let you do that
An operation that increases an index by n without getting out of array borders, with zero-indexed arrays, would be:
index = ( index + n ) % size
If you have arrays starting with 1, and I actually had to do this in Lua:
index = (index + n - 1 ) % size + 1
The answer to your question is, mathematical operations with arrays work better and with less overhead with zero based indexes.
arr