Earlier quoted context omitted.
“machine code” isn't really the zero point that's special nowadays. The code the programmer wrote is compiled to something such as LLVM IR, LLVM IR is further compiled by LLVM to Assembly, this is further compiled by an assembler into machine code, and then the c.p.u. further compiles this to it's internal code as it executes it. “machine code” really is no more special in this chain of events than, say, LLVM IR.
Machine code is special because its the only thing the CPU can actually execute.
Why do arrays start at 0?
641–650 of 702 posts
Re: Why do arrays start at 0?
#642Earlier quoted context omitted.
Machine code is special because its the only thing the CPU can actually execute.
Except if the CPU is microcoded, those instructions might not mean what you think they do, and you need something like Intel's V-Tune to actually understand what the CPU is doing with them.
x86 has a developers manual for this purpose.
Re: Why do arrays start at 0?
#643Earlier quoted context omitted.
Except 1-based indexing is what we use in normal language. We don't use "zeroeth" or "player (number) zero" etc. And the word "first" is shortened to 1st etc. Personally I think we'd be better off if programming languages stuck to the same convention - off-by-1 errors aren't the hardest problems to deal with but they're still annoying.
That's confusing ordinal and cardinal numbers. The element with index 0 is the first number. The element with index 1 is the second number, and so on. Using the term "zeroth" is basically some form of showing off (even though it's kinda fun), but will be utterly confusing when you get to the fifty-second element which is the last in a group of 53 elements.
Re: Why do arrays start at 0?
#644>// if one prisoner fails all are dead (1st try -> tries = 0)
https://gist.github.com/amalic/c107b5289d946b758418778a95fdc...
That being said, it seems to be a junior software engineer issue where the brain isn't wired yet for "0-based" indexing. I don't hear such complaints from more experienced developers who have simply learned to appreciate it because like in my example above it is more intuitive to me.
I have added "and eventually future older me" above because I don't do much coding these days, and my career trajectory looks like it's going to be even less in the future.
Re: Why do arrays start at 0?
#645Earlier quoted context omitted.
Yes, where I'm at — large country in Asia — we count floors starting from 0 (aka G for Ground). Confused me when I visited USA.
G or L (for lobby) followed by 1 isn't uncommon in the US. > Confused me when I visited USA It's applied inconsistently enough to be confusing for natives too!
Re: Why do arrays start at 0?
#646Earlier quoted context omitted.
Except 1-based indexing is what we use in normal language. We don't use "zeroeth" or "player (number) zero" etc. And the word "first" is shortened to 1st etc. Personally I think we'd be better off if programming languages stuck to the same convention - off-by-1 errors aren't the hardest problems to deal with but they're still annoying.
> "player (number) zero" That would be because any game worth playing has at least one player... and so it's natural to continue from there. (In terms of language.)
Re: Why do arrays start at 0?
#647Earlier quoted context omitted.
Except if the CPU is microcoded, those instructions might not mean what you think they do, and you need something like Intel's V-Tune to actually understand what the CPU is doing with them.
> ... to actually understand what the CPU is doing with them. x86 has a developers manual for this purpose.
We are way beyond MS-DOS days and Michael Abrash's books.
Re: Why do arrays start at 0?
#648Earlier quoted context omitted.
They do, it's called the ground floor.
In France, it is called the rez-de-chaussée. The “premier étage” (literally translated as “first floor”) is what the US calls the second floor.
In English you count "floors" and floor is a usable, hard surface on which you can put something, like a chair. That's why a floor on the ground level is treated the same as the floor above it - it is equally good on accommodating chairs, beds, and other stuff.
Re: Why do arrays start at 0?
#649Earlier quoted context omitted.
That's confusing ordinal and cardinal numbers. The element with index 0 is the first number. The element with index 1 is the second number, and so on. Using the term "zeroth" is basically some form of showing off (even though it's kinda fun), but will be utterly confusing when you get to the fifty-second element which is the last in a group of 53 elements.
I'm not confusing them, my point about abbreviating "first" as 1st was that in typical speech we start counting at 1. Nobody says "let's start with item zero on the list". But programmers are stuck with having to say/think "item 0 in the array".
Re: Why do arrays start at 0?
#650Earlier quoted context omitted.
It's basically only x86 among modern ISAs that lets you do base + literal + register * literal, aarch64 only gives you base + register shifted by a literal, and I believe RISC-V is similar: https://gcc.godbolt.org/z/dz768768z
But it will still execute with likely no extra time at all due to OOE and how fast arithmetics are.