25 ms·
One-based is just wrong. I've never been in a zero-based language and wanted one-based, but I go the other way all the time. Arrays beginning with zero are is
by gct 11y ago
One-based is just wrong. I've never been in a zero-based language and wanted one-based, but I go the other way all the time. Arrays beginning with zero are isomorphic to the ring formed by Z modulo N, and you can use a bit mask for modulo with a power-of-two array size. It's not an "implementation detail" that arrays start with zero it's a "zero is important to mathematics" thing.
If I want to build a hash table, a power of two size for the underlying array is a nice performance optimization since you can use a bitmask instead of a modulo operation, and it makes a big performance difference, what does one-based give you other than some nebulous "it just _seems_ simpler to think about" kind of nonsense? I love how we expect people to grok the type system but we're afraid zero-based arrays will scare mathematicians off.
See:
https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_modulo_n https://en.wikipedia.org/wiki/Modular_arithmetic#Integers_mo...