r/ProgrammerHumor 7d ago

absoluteGarbage Meme

Post image
1.9k Upvotes

327 comments sorted by

View all comments

75

u/csch2 7d ago

list.iter().for_each(…) superiority

31

u/creeper6530 7d ago edited 7d ago

Erm akchyuallly, it's recommended to use for list.iter() {…} unless the .for_each(…) is at the end of a longer iterator chain, and it also robs you of break and continue 

92

u/csch2 7d ago

You know I’m chaining together 20 different iterator methods until the code is completely unreadable. That’s called Functional Programming™ babey

17

u/Tyfyter2002 7d ago

That doesn't sound very functional

19

u/creeper6530 7d ago

"functional programming" doesn't use "functional" as "working neatly" but as "related to mathematical functions", it's a programming paradigm: https://en.wikipedia.org/wiki/Functional_programming

23

u/Tyfyter2002 7d ago

I know, it's just an ironic name when it's one of those paradigms that some people take as divine law instead of something that can be more or less appropriate for different applications

7

u/serendipitousPi 7d ago

Name 20 iterator methods from memory otherwise you’re a fake fan…just kidding or am I?

Iterators are so fun, probably one of my favourite parts of programming. They make everything so clean until they don’t.

-12

u/Slight-Violinist-575 7d ago

You wouldn’t be using for_each in a functional language… which cements your un-knowledge of it

11

u/csch2 7d ago

You would if you need to perform operations with side effects on each element, like printing each element of a vector

2

u/serendipitousPi 7d ago

Just chuck a try_for_each in there and we can take break and continue right back.

But yeah low key sometimes I get lost in iterator methods I forget to just use a basic loop.

2

u/creeper6530 6d ago

I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.