It figures this is Java (I think) in that you've gone for pedantic rubbish where ALL you've done is let the programming language do the loop instead of saying it. forEach still loops, but it does so in a re-re ermagahd aherpaderp manner.

To be brutally frank

Image for post
Image for post

Methods like foreach use callbacks. Callbacks are functions (or methods — same thing under the hood) so all you’ve done is introduce the overhead of function calls to EACH loop iteration. That is LESS efficient code that in the case of small snippets like yours could triple the execution time OR MORE. And for what, some paranoid whackjob made up fairy tale about how “loops are bad?”.

Object methods like forEach are the real code smell. And they’re worse in other languages! They’re slow, inefficient, introduce overhead and REDUCE code clarity by sending people who don’t know your code searching for whatever the blazes function/method you’re calling to handle the processing.

Seriously if you think the derpy daisy-chaining of methods, ignorant wrapping of callbacks, creation of excess memory allocations (via trash like IntStream) and so forth is somehow magically “better code” you know nothing about how any of this works under the hood, know even less about writing efficient code, and have a very queer notion of what code clarity is.

I swear you JAVA “objects for everything” nutters are just as bad as the “functional programming” whackjobs when it comes to making up absolute nonsensical BS about… well… .EVERYTHING!

It’s a tragic comedy when your alternative to using loops is to use a object method that internally is just a loop. 100% hurr durrz. I swear folks who think like you when it comes to programming would be SO utterly lost writing Assembly.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store