Skip to content
DevMeme
2749 of 7590
Languages Post #3037 · source on Telegram

Programming Language Smackdown: The Great Loop Debate

Description

This meme uses the four-panel 'We're the Millers' road trip argument format to compare loop constructs across different programming languages. The first panel shows a defensive Jason Sudeikis as 'JavaScript', saying, 'Wait, I can explai-', alluding to its many, sometimes confusing, loop types. The second panel has Jennifer Aniston as 'Python' stating, 'you've for, while and do-while, i only have for and while,' highlighting its simpler approach (though Python lacks a do-while loop, the sentiment stands). The third panel features Emma Roberts as 'Go', looking puzzled and saying, 'for, while? i only have for,' referencing Go's minimalist design where a single 'for' keyword handles all looping. The punchline comes in the fourth panel, with a confused Will Poulter as 'Haskell' asking, 'you guys have loops?'. This joke lands with experienced developers because Haskell is a purely functional language that avoids traditional imperative loops in favor of recursion and higher-order functions like map, making the very concept of a 'loop' foreign to its paradigm

Comments

58
Anonymous ★ Top Pick The difference is simple: imperative programmers ask 'how many times?', while functional programmers ask 'on what data are we mapping this function?'
  1. Anonymous ★ Top Pick

    The difference is simple: imperative programmers ask 'how many times?', while functional programmers ask 'on what data are we mapping this function?'

  2. Anonymous

    JS, Python, and Go can’t decide how many loop keywords the bus needs; the Haskell dev just re-models the trip as a lazy list - iterations only happen if someone observes them, which is exactly how our production dashboards work anyway

  3. Anonymous

    The real plot twist is when you realize Haskell developers have been using map, fold, and recursion to solve every problem while the rest of us are still arguing whether ++i or i++ is more performant in our for loops that the compiler optimizes away anyway

  4. Anonymous

    Haskell developers don't need loops - they just keep calling themselves until the problem goes away. Meanwhile, JavaScript developers are still trying to decide between for, while, do-while, for...in, for...of, forEach, map, reduce, and 'should I just use recursion?' It's the classic trade-off: you can have explicit iteration primitives for every conceivable use case, or you can embrace mathematical elegance and let the compiler figure out how to actually execute your beautifully composed functions. Go took one look at this mess and said 'for is for everything,' proving that sometimes the best design decision is just picking one thing and sticking with it - a philosophy that clearly didn't make it to the JavaScript standards committee

  5. Anonymous

    Go collapses while into for, Python makes for a protocol, JS keeps do-while for spec archaeology, and Haskell just says ‘have you tried folding the monoid?’ - same control flow, four ideologies, one bikeshedded PR

  6. Anonymous

    Haskell devs eyeing loops like COBOL codebases: quaint relics for mortals who fear stack overflows

  7. Anonymous

    JS flexes for/while/do-while; Python just yields; Go ranges with one for; Haskell folds - and the pager still says “infinite loop” at 3 a.m

  8. @deerspangle 5y

    All the cool kids use map, filter, reduce

  9. @sashakity 5y

    how do go programmers do things without while

    1. @chupasaurus 5y

      Their for loop covers while true usage as just for {} or for true {}, which makes it overall as "while with batteries"

      1. @sashakity 5y

        thats odd but handy

    2. Deleted Account 5y

      i like never use while

      1. @chupasaurus 5y

        But every for is while anyway

        1. @sashakity 5y

          reject loops return to goto

          1. @chupasaurus 5y

            BASIC flashbacks in my head

            1. @doodguy1991 5y

              C and C++ has goto as well

              1. @chupasaurus 5y

                Those languages have way more options for shooting the leg.

          2. Deleted Account 5y

            return to lambda calculus

        2. Deleted Account 5y

          i don't think i use for that much too nowadays

    3. @denisndenis 5y

      In functional programming we use recursive functions for loops

      1. @theodolu 5y

        How do you BREAK out of recursion?

        1. @denisndenis 5y

          Just like in any other language - on some exit condition you just don't call the recursive method anymore

          1. @theodolu 5y

            But you need to go all the way back the stack, with loops you just break the loop as soon as you've found something

            1. @denisndenis 5y

              Yep. See my previous message

              1. @theodolu 5y

                Yep, but tail recursion still uses stack of the os

        2. @denisndenis 5y

          tailrec annotation checks if this recursive function is tail recursion. Such functions are optimized in functional languages (here you see Scala) in a way so they are stack-safe (they becomes loops under the cape).

  10. @chekoopa 5y

    Tail recursion ahoy!

  11. @denisndenis 5y

    Yes, but it takes just one stack frame since it is just a loop under the cape.

    1. @theodolu 5y

      I was using iterative dfs to find a node in the graph and then print the path, as soon as I find it I just break the loop and return the result. How do I do that with recursion?

      1. @denisndenis 5y

        Well i am not sure about specific of this task, but nothing stops you from using IFs in recursion:

        1. @theodolu 5y

          Yes, I can add another if to each call and a parameter to the function which says if the node is found or not, but that will quadruple the time of excexution

          1. @denisndenis 5y

            I can't really argue with that since i have no understanding of that task. Why would if and extra parameter quadruple the time? It is not the same as adding extra recursive/iterative calls.

            1. @theodolu 5y

              Because first you have to go down the graph and then up the stack, calling double Ifs each time. Although one if can be faster than another, and goind up the stack can be faster than going down the graph, so quadruple is worst case scenario

              1. Deleted Account 5y

                if you are looking for speed, python should not be your goto

                1. @theodolu 5y

                  I can use Javascript but python with numba is faster

                  1. Deleted Account 5y

                    at least do it in kotlin/c# (i don't think c++ will be an option for you)

                    1. @theodolu 5y

                      Y tho

                  2. @chupasaurus 5y

                    Anything with C bindings is faster

                    1. @theodolu 5y

                      Flipping bits in ram with a piece of uranium is even faster

                      1. @chupasaurus 5y

                        Polonium would be better if we don't count artificial elements and short-lived ones

          2. @Supuhstar 5y

            What language are you using where a single branching statement quadruples execution time? O.o

  12. @UQuark 5y

    I'd like to ask Haskell devs AFAIK, you use recursion instead of loops But how do you deal with stack overflow? Do function calls work completely different in Haskell?

    1. Deleted Account 5y

      tco exists in fp langs, which eliminates recursion and replaces it with what is effectively loops

      1. @UQuark 5y

        So actually you don't have recursion in Haskell but you do have loops

        1. Deleted Account 5y

          no, it's all recursion, but it's sometimes optimized away by the compiler

          1. @UQuark 5y

            I have another question Is Haskell actually useful in modern programming? Like, can you effectively develop a GUI application or a backend for a product?

            1. Deleted Account 5y

              backend yes, compilers yes, i don't think gui will be easy, and certainly not embedded (it doesn't fit there)

              1. @gDanix 5y

                You can do really nice GUIs with Haskell but in web. There's a list of GUI toolkits, but I definitively recommend to take a look at Integrated Haskell Platform (IHP)

                1. Deleted Account 5y

                  well, not that interested in the web, but thanks for advice anyway

                  1. @gDanix 5y

                    I wasn't, and I think the web itself it's an gigantic, unfixable mess. But since HTML5 it lets you build most of the everyday applications, so having IHP and Elm around is a nice way for not getting your hands dirty with Windows or shittylangs

                    1. Deleted Account 5y

                      yeah, using webapps is ways better than using windows, i agree

            2. @Supuhstar 5y

              It's best for things like what JavaScript does

        2. Deleted Account 5y

          also, it may not even be a loop too, bc haskell is a lazy language, so many function calls can be inlined away as transformations to the data

          1. Deleted Account 5y

            and it can even avoid some allocations too

    2. @Supuhstar 5y

      Haskell's interpreter is really good at Tail End Recursion, so it optimizes these for the target CPU. Since all CPUs these days are practical Turing Machines, it converts a lot of recursion into loops and branches

      1. @UQuark 5y

        Wait, Haskell is interpreted?

        1. @Supuhstar 5y

          When I learned it in ~2014 it was with an interpreter. I'm sure there's compilers too

        2. Deleted Account 5y

          GHC is the compiler, GHCi is the interpreter. I imagine both do similar optimisations

Use J and K for navigation