Zero-Based Apple Counting Gets Roasted
Description
A screenshot of a tweet shows user layla @slphrr saying, "wow programmers must be really dumb" above a quoted tweet from "gbae the app dev" @daboi dated Dec 2. The quoted tweet asks, "as a programmer - how many apples do you count?" and includes an older meme image reading "YOU KNOW YOU'RE A PROGRAMMER WHEN.." above four red apples, then "YOU COUNT 3 APPLES.." at the bottom. The joke relies on programmers confusing cardinal counts with zero-based indexing, treating the fourth apple's index as the number of apples. The top tweet punctures the classic beginner programmer joke by pointing out that confusing indexes with counts is not clever software engineering, just a bad abstraction leak.
Comments
40Comment deleted
Counting from zero is fine; returning the last index as the aggregate is how you get promoted directly to incident commander.
I think some programming languages don't start indexing from 0 Comment deleted
like lisp iirc Comment deleted
Yep. Awk, Cobol, Lua, Bash (runs away real fast)… UPD: not Bash Comment deleted
Oh shit those cultists raised again from the ancient ruins Comment deleted
FORTRAN! (Evil laugh) Comment deleted
Bash starts at 0 Comment deleted
Yeah, it's Zsh that uses 1-indexing And in Ada you can set initial index to whatever you like. Comment deleted
Technically that's even true with Lua. But terms and conditions apply 🤣 Comment deleted
Like other languages with only associative arrays (eg. AWK) you can use whatever for indexing. Pi with various number of digits? Emoji? Whitespace? Have fun. Ada is different though. It has true arrays mapping to a memory region. It also allows you to create subtype of integer type bounded to custom min and max values. And when you combine these two you get a typesafe* arrays with arbitrary index range. * terms and conditions apply. If you want true safety without runtime checks it allows you to write a proof in SPARK to formally verify you don't exceed the bounds. Comment deleted
yes, you are right. The arguments $1 $2 etc start from 1 (0 points to the executable itself) and it confused me, but the arrays start at 0. $ echo $BASH_VERSION 4.3.46(1)-release $ myArray=("cat" "dog" "mouse" "frog") $ echo ${myArray} cat $ echo ${myArray[0]} cat $ echo ${myArray[1]} dog Comment deleted
Btw, try this: declare -p myArray I find this extremely valuable for debugging and tracing as it also allows to distinguish scopes etc. Comment deleted
Wow! This is super nice, thanks. Comment deleted
Lua Comment deleted
But the count is 4 Comment deleted
array.length is 4 last index is 3 Comment deleted
The design spec asked for count, not last index Comment deleted
count == length Comment deleted
Exactly Comment deleted
So what's the problem? Comment deleted
Seemed like that original commenter was trying to justify 3 as a potential answer Comment deleted
Yeah, but you still count 4. A more accurate way to put this would be to put an arrow next to the last one and say "this is the third apple" Comment deleted
App development doesn't require 1st grade math knowledge, noted Comment deleted
My math is crap but I learned how to calculate reflection ray with trial and error Comment deleted
it's not about math it's about how you approach the situation Comment deleted
Not only it is not required, but also strictly forbidden if you develop apps with node. Just counting hello world dependencies can make a sane person question his life choices Comment deleted
I can only see 100 apples... Comment deleted
One apple and 3 references. Comment deleted
i see 1 tex and 4 render targets Comment deleted
Only one Comment deleted
... and 4 references to it? 🤗 Comment deleted
So 4 is objectively correct, and 3 is just dumb, there's really not a way to justify 3 Comment deleted
Exactly Comment deleted
It's -1 anyway Comment deleted
one apple class and 4 instances Comment deleted
bruh, the count is 4, but the index of the last element is 3. It's a big difference. Leyla is actually right Comment deleted
Indexing and counting is different story Comment deleted
I can see 10 G for those laptops Comment deleted
The index of the last one is 3 but the count is 4. Comment deleted
0 1 2 3 Comment deleted