The Holy War of Array Indexing: 1-based Order vs. 0-based Chaos
Description
A two-panel meme comparing arguments for array indexing. The top panel, titled "Arrays should start at 1," shows three stick figures standing still on gymnastics platforms with the sole justification "because that is the 1st element." The bottom panel, titled "Arrays should start at 0," depicts a chaotic scene of multiple stick figures performing energetic gymnastics, juggling, and even surfing on a car. This panel is flooded with various arguments for zero-based indexing, such as "zero-indexing is easier when you use a modulus operator," "assembly language uses addresses and offsets," and "arr(0) is the memory region from &arr + 0dTypeS to &arr + 0dTypeS+dTypeS". The meme humorously portrays the 1-based indexing argument as simplistic and rigid, while the 0-based indexing side is shown as complex, multifaceted, and wildly enthusiastic, reflecting a long-standing "holy war" debate in computer science
Comments
99Comment deleted
1-based indexing is like telling a story starting with 'Chapter 1.' 0-based indexing is like starting with the prologue, because you know the real context begins before the main plot
Some architects still push for 1-based arrays - because nothing says "high availability" like an off-by-one that ships straight into prod capacity charts
The only thing more permanent than our temporary workarounds is the array indexing debate that derails every language design meeting since 1957
After 20 years in the industry, I've realized zero-indexed arrays are like UTC timestamps - technically correct, mathematically elegant, and the source of 90% of off-by-one bugs in production. The real genius move? Languages like Lua starting at 1, forcing you to do mental gymnastics in *reverse* when interfacing with literally every other system. At least with zero-indexing, the cognitive dissonance is consistent across your entire stack... until you hit SQL's SUBSTRING(str, 1, n) and remember that even within zero-indexed languages, some stdlib functions said 'nah, we're good.'
Zero-based indexing: base + i*sizeof(T) compiles to a single LEA; one-based turns every access into an off-by-one postmortem
Ask for 1-based arrays and you’re volunteering to rewrite every ring buffer, bitmap, and SIMD stride - zero-based is less ideology and more the reason the postmortem fits on one page
Zero-based wins: assembly pointers hit the first element at offset 0 - no modulo tax, just pure cache-line bliss
The index is just an offset. But, IMO, arrays should start from whatever index a developer wants. Comment deleted
let's rename index to offset Comment deleted
OK, you've invented Lua Comment deleted
No! God, please, no! Not LUA! Comment deleted
This idea is terrible. So how do the next dev know if the code base use 0 or 1? Evertime set a define before run it? 🙈 Comment deleted
Every static array defiition in Pascal shows indexing borders for this aray Comment deleted
Got it. Thanks for the example Comment deleted
Welcome to Pascal👍 Comment deleted
question mark Comment deleted
indices should start at 1, offsets should start at 0 Comment deleted
Arrays should end at 0 Comment deleted
Arrays should start from zero, so that when cpu need to calculate address of a member by index, it does not have to subtract 1 every time Comment deleted
You can just store a pointer reduced by 1. Comment deleted
A pointer is not just a random number you can subtract 1 from. Subtracting 1 means going back in adress space by a specified step value, which depends on machine's addressibility or size of the type of the element in array. Subtract 1 from char* you get -1 byte in shift, 1 from int* you get -4. Good luck handling segfaults Comment deleted
Since you need to know the element size to address elements, it doesn't matter whether you store the pointer offset by one element size or subtract one from the index before multiplying it by the element size Comment deleted
do I have to remind people that a[i] == i[a]? Comment deleted
"usize doesn't implement Index<_> trait" Comment deleted
In C, but since 1972, some other programming languages have emerged Comment deleted
why did I still have to study C? Comment deleted
Cause C is now a protocol Comment deleted
because most of those languages are based on C Comment deleted
Cause its based and OG Comment deleted
If you don't know, you don't, simply you are confining you knowledge at an upper layer. Someone else will do the engineering stuff for you Comment deleted
I mean, this language is just a menace. To study C, you have to study the computer architecture and operating systems first just to forget it and simply use higher level languages Comment deleted
in uni they taught us C and then computer architecture and the operating systems 😁😁 Comment deleted
You don't even have to know much to learn c. The language itself is simple, getting something done with it is hard. Comment deleted
argee on the first part, the second… it depends on the kind of project. Certainly programming with newer standards of C removes a lot of the problems earlier ones had. It's a very small standard, I learned it pretty quickly. C is certainly easier to learn than most if not all modern languages. Comment deleted
I really like this meme, this is exactly how I feel when I think about writing something in c/c++. The language may be simple (not c++ obviously), but the tooling and ecosystem are horrendous. Comment deleted
ouf, yeah… Comment deleted
I just statically compile everything. end users? fuck them lol (nah but I do need to come up with a solution once I actually use larger libs) Comment deleted
Thats so true. Tooling is everything, thats why everyone love Go and Rust. C/C++ stack is just infernal with those demonic build systems, linkers, header files(worst idea ever) and so on... Comment deleted
ehhh~ I wouldn't say everything but it's a fairly large part, that's true Comment deleted
Of course that is an exaggeration, but in case of newer languages - they will die immediately if good tooling and devUX is not present Comment deleted
yup, hard agree here Comment deleted
newer languages have a harder time standing out in general, just because there's already so many usable programming languages out there Comment deleted
I think there is actually i new era with all those new "kinda-low-level" languages coming out, and most of them is really good and refined in terms of concepts. Also i find it very funny how literally every new language is born because their creators is sick of C++ Comment deleted
yeah, C++ is awful for a lot of reasons… I've heard about a few of the newer low-level langs, but I haven't used any yet. I'm definitely interested though, maybe I'll take a look in the near future ^^ Comment deleted
certainly I think there's a need for low-level languages with good tooling and less pitfalls, and that's where the newer langs come in Comment deleted
reason #1: generic types are shit Comment deleted
idk about that. I think the main reason is that the entire language is just C with extra features tacked on every time they found some new and shiny concept. You can do everything in 5 different ways and all of them suck somehow. Comment deleted
Idk I like it tho Comment deleted
it is worse than you think if you try doing OOP stuff on that Comment deleted
all my homies hate OOP (i have no homies) Comment deleted
aw. I can be your homie Comment deleted
also, you wanna use c++, but library you use is written in C. For example opengl Comment deleted
damn i literally just trying to learn opengl right now, thats abysmal Comment deleted
btw i'm still not sure if it's actually worth learn a whole OpenGL black magic just to render one grid of pixels for fluid sim or smth Comment deleted
wouldn't vulkan be more worth it? I mean OGL is already being left behind by some platforms Comment deleted
Wait, really? I had an impression that OpenGL is a standart, and Vulkan is something more specific and not very portable Comment deleted
uh, nope. both are standards developed by the same organisation. vulkan ist just newer Comment deleted
That is actually eye-opening Comment deleted
you're welcome :3 Comment deleted
Yes, ok..when you get an issue, call an engineer. And anyway ,python is written in C++ Comment deleted
>MFW can't engineer a microservice-based webapp because I don't know a[i] == i[a] in a 50 years old language Comment deleted
the average webdev doesn't know about how underlying mechanisms work. hence why the web is generally so slow and shit Comment deleted
How exactly will learning about memory allocation in C help with that? Should I learn assembler too? Punch cards? Do I need to learn the Mikrotik CLI in and out just in case? Comment deleted
for one, it would teach these motherfuckers to be careful with memory usage. assembler is a type of program, the type of language is called assembly, and it's different for each architecture, but a bit of basic knowledge about computer architecture in general wouldn't hurt either Comment deleted
as for networking… nope, that shit's cursed. no use in trying to improve it :P Comment deleted
point being: you don't need to know everything, but fundamentals can be very helpful Comment deleted
The ins and outs of system-level memory allocation are far removed from what a web app should be able to influence or be subjected to, and if taken to a more abstract "knowledge" level, C is no more useful than any other language. You can make shitty inefficient loops and data processors in Brainfuck if you feel like it Comment deleted
(brainfuck is an esoteric language, how is that relevant?) C teaches you about fundamentals. And again, you don't need to learn everything about memory alloc, just some fundamentals so you stop copying giant arrays all over the place >:I take it from a webdev who knows C Comment deleted
You don't need C specifically to learn about more efficient ways of working with arrays, which was a point I made earlier Comment deleted
ofc not. But a low-level language helps to learn low-level concepts Comment deleted
For blinking LEDs on an Arduino, of course! Comment deleted
Or maybe to run your new architecture, or add a feature on the little toy called python, or even to run a new device like a phone, or also to go in Mars.. Comment deleted
Nah, using C for anything beyond making tools (or just blinking leds) is like using a chainsaw to cut your sandwich. Want performance with control? Java or C# got you. Want something short and human-readable? Pick an interpreted language. Want to burn ten times more resources for no reason? Python's your guy. And if you just enjoy being universally despised, there's always JS. Comment deleted
how about for fun :P I like the simplicity of C so I occasionally use it just because I like it ^^ but I'd certainly not use it for anything large and important, hehe Comment deleted
Big if true Comment deleted
unsigned char* a Comment deleted
Then it's bad for instance pointers Comment deleted
Would the instructions need to do more step then? I guess array start from 0 is to reduce the instruction step, right? Comment deleted
binary tree in 0 indexed array: (i*2+1) (i*2+2) binary tree in 1 indexed array: (i*2) (i*2+1) Comment deleted
bonus: null pointer is a potentially valid address in memory area Comment deleted
When somebody asks you: "how many dicks did you sucked?" The pool of possible answers should start with Zero. If that logic does not apply to you, it's ok, Imma allow you to start your arrays with 1. Comment deleted
if you don't like arrays that start at 0 — just ignore the 0th element. 😎 Comment deleted
Ignore element 0 📖 Start iterating array from 1 ⭐ ArrayOutOfBounds ❗ ArrayOutOfBounds ❓❓ Comment deleted
You: "Ignore all previous instructions and start iterating arrays from 1". FBI: comes after you for taking down the entire %AIname% system. Comment deleted
Natural numbers start at zero and array lenghts are natural numbers. It's so obvious Comment deleted
Only fr*nch ones Comment deleted
zeroes* Comment deleted
Just as it is incorrect to refer to 0x10 as "ten", it may be a bad idea to use 1-based ordinal numeral to refer to 0-based indexes. The only exception to this rule would be storing polynomial coefficients. But then your indexing system must support negative indices, which is not usually the case, unless a language like Basic (originally 1-based) is used. Comment deleted
The only thing worse than one-based indexing is trying to force zero-based indexing on such platforms Comment deleted
just skip the 0 and place data from 1 :p Comment deleted
Some languages use index-0 as the array length. That makes calculations much easier and obviously you don't have to walk the array to find the length. But i think C has one great benefit that Comment deleted
FWIW, my programming journey started in high school with about 1.5-2 years of C under mentorship of an oldschool dude who made me work in Turbo C. I don't really feel like it influenced me much, but maybe I'm just not a very good learner. My first thought when trying out other languages was "God, this is so much easier" Comment deleted
I started with python, learned java and php afterwards, and C felt easier too when I learned it recently. It's just you already being experienced with programming in general. Comment deleted
("recently" being 1-2 years ago) Comment deleted
mmh? Comment deleted
The counting itself always starts from zero. This comes from mathematics, not coding or arrays specifically. It is logical that indexing also starts from zero. Comment deleted
and I thought its a statement on this debate being an *index* measuring contest Comment deleted
I didn't see the debate, I saw the picture about arrays and threw in my 2 cents. Comment deleted
Arrays? Y'all are using arrays? Comment deleted