Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
That's a fair abstraction IMO: hiding a pesky implementation detail to prevent off-by-one errors. I wonder why JS doesn't do this all things considered?
-
@SuspiciousBug Off-by-one errors are prevented by strong standards. While starting lists from 1 may improve the experience of people who never have and never will program in another language, everyone switching to and from Lua gets surprised. Few people apart from total newbies actually think while writing a for loop; it's just an atom to most of us. Having to write that atom differently in Lua than in every other language is an off-by-one error factory.
-
@ALMST That is why the day starts at 1:01:01 and not at 0:00 ?
GND has a voltage of 1V, not 0V.
A distance of 1 km is actually nothing, if you want to drive 0 km you have to drive backwards.
If you have no money in your bank account, you have 1€ + 1ct, not 0€. -
@SuspiciousBug I would argue a lot more off by one errors are caused by arrays starting whit 1 rather than 0.
From a mathematical point of view, 0 makes sense. To be honest, from every point of view 0 makes the most sense.
They could also start at index π -
iiii94081y@happygimp0 as a certified mathematician, I can assure you that math does not give any more sense to counting from zero. And to be fair, the most common counting in math is from one. This is exactly why Matlab uses this as well, to not confuse mathematicians who are not programmers.
Counting from zero is only a thing because of the index being a literal offset from the _first_ element in an array. -
@happygimp0 That applies universally to C, and in some cases C++. Should all languages use === for equality comparison too because [] == 0?
Related Rants
In Lua arrays start with 1 by default. Please kill me.
rant
are you fucking serious
lua