Skip to content
DevMeme
5223 of 7590
CS Fundamentals Post #5727 · source on Telegram

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

40
Anonymous ★ Top Pick Counting from zero is fine; returning the last index as the aggregate is how you get promoted directly to incident commander.
  1. Anonymous ★ Top Pick

    Counting from zero is fine; returning the last index as the aggregate is how you get promoted directly to incident commander.

  2. @callofvoid0 2y

    I think some programming languages don't start indexing from 0

    1. @callofvoid0 2y

      like lisp iirc

    2. @kitbot256 2y

      Yep. Awk, Cobol, Lua, Bash (runs away real fast)… UPD: not Bash

      1. @callofvoid0 2y

        Oh shit those cultists raised again from the ancient ruins

        1. @kitbot256 2y

          FORTRAN! (Evil laugh)

      2. @Assarbad 2y

        Bash starts at 0

        1. @CcxCZ 2y

          Yeah, it's Zsh that uses 1-indexing And in Ada you can set initial index to whatever you like.

          1. @Assarbad 2y

            Technically that's even true with Lua. But terms and conditions apply 🤣

            1. @CcxCZ 2y

              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.

        2. @kitbot256 2y

          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

          1. @Assarbad 2y

            Btw, try this: declare -p myArray I find this extremely valuable for debugging and tracing as it also allows to distinguish scopes etc.

            1. @kitbot256 2y

              Wow! This is super nice, thanks.

    3. Deleted Account 2y

      Lua

  3. @buffy_bara 2y

    But the count is 4

    1. @callofvoid0 2y

      array.length is 4 last index is 3

      1. @deerspangle 2y

        The design spec asked for count, not last index

        1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

          count == length

          1. @deerspangle 2y

            Exactly

            1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

              So what's the problem?

              1. @deerspangle 2y

                Seemed like that original commenter was trying to justify 3 as a potential answer

      2. @CCZeroOne 2y

        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"

  4. @YaroST12 2y

    App development doesn't require 1st grade math knowledge, noted

    1. @callofvoid0 2y

      My math is crap but I learned how to calculate reflection ray with trial and error

    2. @callofvoid0 2y

      it's not about math it's about how you approach the situation

    3. @keeborgue 2y

      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

  5. @async_andrew 2y

    I can only see 100 apples...

  6. @Araalith 2y

    One apple and 3 references.

  7. @Algoinde 2y

    i see 1 tex and 4 render targets

  8. Deleted Account 2y

    Only one

    1. @SamsonovAnton 2y

      ... and 4 references to it? 🤗

  9. @deerspangle 2y

    So 4 is objectively correct, and 3 is just dumb, there's really not a way to justify 3

    1. @ZgGPuo8dZef58K6hxxGVj3Z2 2y

      Exactly

  10. @Sp1cyP3pp3r 2y

    It's -1 anyway

  11. @callofvoid0 2y

    one apple class and 4 instances

  12. @IHateCupsAndDonuts 2y

    bruh, the count is 4, but the index of the last element is 3. It's a big difference. Leyla is actually right

  13. @Saeid025 2y

    Indexing and counting is different story

  14. @phpzapecanus 2y

    I can see 10 G for those laptops

  15. @FunnyGuyU 2y

    The index of the last one is 3 but the count is 4.

  16. @plusdanshi69 2y

    0 1 2 3

Use J and K for navigation