• embed_me@programming.dev
    link
    fedilink
    arrow-up
    12
    ·
    2 days ago

    I don’t get your point. Just because the image gets repeated in the 4th panel doesn’t mean its recursion. It can be an infinite while loop with a state.

    Now that I think about it, a recursion without a base/break condition is just an infinite loop with a state

    • entwine@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      24 hours ago

      Ackshually, the meme is encoded using progressively smaller images nested into the fourth panel of the comic. Each fourth panel is effectively a nested function call to the original comic procedure, which more closely represents recursion than an infinite loop.

      For an infinite loop, one might instead lay out the 3 unique panels horizontally, and just memcpy them into rows below, creating a table. That’s a regression in humor, but it’d fix the bug.

      So I agree with @ryannathans@aussie.zone’s review; The joke is about infinite loops, but the visual gag is about recursion.

      • orbitz@lemmy.ca
        link
        fedilink
        arrow-up
        2
        ·
        21 hours ago

        Lol that’s exactly how I saw it as well. Recursive gets those nesting dolls look in my head, loops are the same size but repeated, even if infinite. Yes even if the code is almost the same since you can write a loop recursively anyways (okay haven’t tested but seems like it’d work mostly fine but not always as clean).

        I think the beauty of it is that the joke can be amusing in multiple ways. Those are the best jokes to me, cause I can think of different ways the next time I see them.

    • AllHailTheSheep@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      2 days ago

      I think modern compilers do actually compile recursion to be equivalent with an iterative model.

      edit: yes when possible they will compile to be iterative, but if it can’t be written iteratively it will be a series of calls and returns. depends on the specific type of recursion it looks like.

      • Buddahriffic@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        2 days ago

        At one point I developed a habit of converting any recursive algorithm I was writing into a loop instead, since I knew function calls have overhead and all recursion really does is lets you use the calling stack and flow control as an invisible data structure.

        Then I got a question about parsing brackets properly during an interview and wrote a loop-based parser to solve it and the guy had to fish for a bit before I remembered recursion and realized that’s the answer he was looking for. My mind just wouldn’t consider using a whole calling stack when an integer would do the trick faster.

        • CrypticCoffee@lemmy.ml
          link
          fedilink
          arrow-up
          4
          ·
          edit-2
          1 day ago

          Most times overhead is less important than readability and maintainability of code. If someone cannot read your code, they’ll mess it up far worse.

          Optimisation is for bottlenecks. No point making code run in 0.01ms rather than 0.02 if it later hits at 0.7s bottleneck like file io or DB. For most things, readability is everything unless you’re developing operating systems or close to metal libraries. Many compilers will inline functions anyway so the only gain is increased suffering of colleagues and later bugs in production when it’s modified by someone else. Cognitive load is very important and why many static code analysis tools pick it up.

          • Buddahriffic@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            1 day ago

            One has a function that takes the next node as an argument, another just sets that up in a loop. Personally, I found the loop one a bit easier to visualize and debug via stepping through code, though admittedly the difference isn’t huge.