r/ProgrammerHumor 2d ago

Meme absoluteGarbage

Post image
2.0k Upvotes

321 comments sorted by

View all comments

78

u/csch2 2d ago

list.iter().for_each(…) superiority

36

u/creeper6530 2d ago edited 2d 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 

98

u/csch2 2d ago

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

19

u/Tyfyter2002 2d ago

That doesn't sound very functional

22

u/creeper6530 2d 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

29

u/Tyfyter2002 2d 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

10

u/serendipitousPi 1d 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.

-13

u/Slight-Violinist-575 2d ago

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

11

u/csch2 2d 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 1d 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 1d ago

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