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
58Comment deleted
The difference is simple: imperative programmers ask 'how many times?', while functional programmers ask 'on what data are we mapping this function?'
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
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
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
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
Haskell devs eyeing loops like COBOL codebases: quaint relics for mortals who fear stack overflows
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
All the cool kids use map, filter, reduce Comment deleted
how do go programmers do things without while Comment deleted
Their for loop covers while true usage as just for {} or for true {}, which makes it overall as "while with batteries" Comment deleted
thats odd but handy Comment deleted
i like never use while Comment deleted
But every for is while anyway Comment deleted
reject loops return to goto Comment deleted
BASIC flashbacks in my head Comment deleted
C and C++ has goto as well Comment deleted
Those languages have way more options for shooting the leg. Comment deleted
return to lambda calculus Comment deleted
i don't think i use for that much too nowadays Comment deleted
In functional programming we use recursive functions for loops Comment deleted
How do you BREAK out of recursion? Comment deleted
Just like in any other language - on some exit condition you just don't call the recursive method anymore Comment deleted
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 Comment deleted
Yep. See my previous message Comment deleted
Yep, but tail recursion still uses stack of the os Comment deleted
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). Comment deleted
Tail recursion ahoy! Comment deleted
Yes, but it takes just one stack frame since it is just a loop under the cape. Comment deleted
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? Comment deleted
Well i am not sure about specific of this task, but nothing stops you from using IFs in recursion: Comment deleted
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 Comment deleted
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. Comment deleted
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 Comment deleted
if you are looking for speed, python should not be your goto Comment deleted
I can use Javascript but python with numba is faster Comment deleted
at least do it in kotlin/c# (i don't think c++ will be an option for you) Comment deleted
Y tho Comment deleted
Anything with C bindings is faster Comment deleted
Flipping bits in ram with a piece of uranium is even faster Comment deleted
Polonium would be better if we don't count artificial elements and short-lived ones Comment deleted
What language are you using where a single branching statement quadruples execution time? O.o Comment deleted
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? Comment deleted
tco exists in fp langs, which eliminates recursion and replaces it with what is effectively loops Comment deleted
So actually you don't have recursion in Haskell but you do have loops Comment deleted
no, it's all recursion, but it's sometimes optimized away by the compiler Comment deleted
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? Comment deleted
backend yes, compilers yes, i don't think gui will be easy, and certainly not embedded (it doesn't fit there) Comment deleted
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) Comment deleted
well, not that interested in the web, but thanks for advice anyway Comment deleted
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 Comment deleted
yeah, using webapps is ways better than using windows, i agree Comment deleted
It's best for things like what JavaScript does Comment deleted
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 Comment deleted
and it can even avoid some allocations too Comment deleted
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 Comment deleted
Wait, Haskell is interpreted? Comment deleted
When I learned it in ~2014 it was with an interpreter. I'm sure there's compilers too Comment deleted
GHC is the compiler, GHCi is the interpreter. I imagine both do similar optimisations Comment deleted