all 36 comments

sorted by: hot top controversial new old
[–] 57 points 1 year ago

Cute — though the visual gag fits a little better with infinite recursion that infinite loop.

  • source
  • [–] 52 points 1 year ago (2 children)
    [–] 31 points 1 year ago

    Long ago, I made a four line recursive HTML that did this with frames. Browsers didn’t have protection against that at the time, so if you opened it and let it run, your machine would lock up.

  • source
  • [–] 18 points 1 year ago (8 children)

    Recursion isn't the same as as infinite loop

  • source
  • hideshow 8 child comments
  • [–] 11 points 1 year ago (7 children)

    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

  • source
  • parent
  • hideshow 7 child comments
  • [–] 6 points 1 year ago (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year 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.

  • source
  • parent
  • [–] 3 points 1 year ago* (4 children)

    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.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 3 points 1 year ago (2 children)

    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.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 4 points 1 year ago* (1 child)

    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.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year 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.

  • source
  • parent
  • [–] 15 points 1 year ago* (4 children)

    The compiler (in C) is allowed to assume that infinite loops eventually terminate. This can lead to these kinds of loops not actually running forever when built with an optimizing compiler.

    ISO/IEC 9899:2017 §6.8.5 “Iteration statements”, paragraph 6:

    “An iteration statement may be assumed by the implementation to terminate if its controlling expression is not a constant expression, and none of the following operations are performed in its body, controlling expression or (in the case of a for statement) its expression-3: – input/output operations – accessing a volatile object – synchronization or atomic operations."

    It can, for example, simply optimize it away, assuming non-productive infinite loops are stupid and not reflective of what the code will actually do.

  • source
  • hideshow 4 child comments
  • [–] 7 points 1 year ago (1 child)

    for example, simply optimize it away

    Yeah, that example makes it reasonable. But the optimizer can do ridiculous stuff when it proves the loop never terminates and also assume it terminates.

    The most famous example of UB bullshit is when some compilers run code that is impossible to reach just because there's an infinite loop on the file (not even in the same function).

  • source
  • parent
  • hideshow 1 child comment
  • [–] 1 point 1 year ago (1 child)

    if its controlling expression is not a constant expression

    Pretty big caveat. If I'm reading this right true definitely qualifies as a constant expression and the loop in the meme would therefore not be optimized away.

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 1 year ago

    There's also this part of the standard that throws a wrench into this hypothesis:

    §5.1.2.3/4: (Program execution, Observable behavior):

    Accesses to volatile objects and calls to library I/O functions are observable behavior. The implementation may perform any transformation of a program, provided that the resulting program’s observable behavior is not changed.

    So it seems that running forever isn't an observable property that must be preserved when code is transformed.

    Still, I think compilers try to not surprise the developer too badly and would recognize a trivial loop most of the time.

  • source
  • parent
  • [–] 13 points 1 year ago (2 children)

    CPU temp will be my break statement.

  • source
  • hideshow 2 child comments
  • [–] 11 points 1 year ago* (last edited 1 year ago) (5 children)

    Very much needed for embedded systems, but I’m more of a for (;;) guy myself!

  • source
  • hideshow 5 child comments
  • [–] 3 points 1 year ago (4 children)
  • [–] 11 points 1 year ago (3 children)

    It’s C, but the unusual look of having two semicolons is the reason why I prefer it over while (True). It feels more like “here is the weird part”.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 8 points 1 year ago (1 child)

    Always check for infinite cat girl errors.

  • source
  • hideshow 1 child comment
  • [–] 7 points 1 year ago

    It's saddening to me how many times I've actually come across this in production.

    Just because the code works doesn't mean it should ship.

  • source
  • [–] 4 points 1 year ago (1 child)

    You can have a non-infinite loop without a break statement, you just need a return statement in it. Also for(;;) is much faster to write than while(true).

  • source
  • hideshow 1 child comment
  • Yes, but the latter is easier to read. I know what the former is, but my colleague could definitely use additional brain cells. And if they don't understand it, I'll be the one explaining. That's also the reason for not using abbreviations besides the most common ones in variable names. Always assume your code will be read by a typewriter monkey.

  • source
  • parent
  • [–] 2 points 1 year ago

    Imagine seriously using break... when I was young we had a break, it's called SIGKILL. And we liked it this way!

  • source
  • [–] 2 points 1 year ago

    A billion years ago, I worked for a place that was using Cold Fusion.

    There was this one project that had a loop with a break condition, but the devs kept accidentally putting errors in the break logic. The project was pretty processor intensive. I got calls 5-6 times a day to reset the CF server because stopping the HTML page wouldn't do #$%^

    Can you guys please just add a second break module so you can just load another page and cause the project to abort? hell make it dump a file in /tmp, whatever....

  • source
  • [–] 3 points 1 year ago*

    Sometimes break is undesirable. But if you want an infinite loop, please please please include a sleep. Not doing this is why my CPU stays at 100%.

  • source