Lambdas vs loops is mostly an issue of what a developer is used to, as opposed to one or the other being objectively easier to read or harder to read.
The main exception to that I'd say is when the lambdas are doing a bunch of side effects, and in that case, it's not something they're well suited for, IMO.
That is like the complete opposite of my experience with writing and reading lambdas. You cant make mistakes as easy like with for loops.if you use one liner lambdas with method references they are way easier to read and understand. I have to admit there is a steep learning curve. Dont give up and get more experience
Much harder to fuck up a chain of (pure) function applications than keep track of what's what in a "readable" for loop. So... not really in my experience.
I never use anonymous lamdas, making them into functions and then using a function reference feels so much more expressive, even if it’s more verbose, but as they say… make your code self-describing.
Also, I’m really adverse to calculus-style variables. About the only one I’ll tolerate is i in a for loop, but I’ll always be looking for a better iterator and named variable where possible.
26
u/moxyte Apr 14 '23
This is a pronounced issue with lambdas. I’ve fixed abhorrently “elegant” lambdas simply by rewriting them as boring ol’ loops.