News for hackers. Stuff that matters.
Re:Cursed Elixir by dnautics on Monday October 19, 2020 @01:40AM (#24823597)
I think also we have learned why map/reduce or functional recursion is better than for loops - because the state of the system is explicitly contained; with a for loop you could literally mutate anything in scope, so the cognitive burden to understanding the process is potentially unbounded; with map, your state between iterations is nothing, and with reduce, it's strictly what you can stash in your accumulator.

I was laughing at myself the other week because I was having so much trouble writing a for loop because I had gotten used to the explicitness of the functional iteration operatiors

Re:Cursed Elixir by rkangel on Monday October 19, 2020 @05:18AM (#24824613)
> with a for loop you could literally mutate anything in scope

That depends on the language. In Elixir for instance, you can't mutate anything. Elixir does have 'for comprehensions', and there are things that you can express very clearly in what is effectively a for loop that would be much harder to read in a chain of iterators.

Re:Cursed Elixir by dnautics on Monday October 19, 2020 @11:12AM (#24827074)
That's not strictly true. You could use the process dictionary to keep hidden mutable state in the for loop. Don't do this.
Re:Cursed Elixir by thedanbob on Monday October 19, 2020 @07:10AM (#24825200)
Same here. I maintain around 30 small-to-medium size Ruby projects and in all that code I can only remember writing a single for loop. On the plus side, I am highly confident that code works right since I spent so much time thinking about it!
Re:Cursed Elixir by higerordermap on Monday October 19, 2020 @09:43AM (#24826276)
Mutation is the scapegoat here. It's all about expressing intent.

Eg: I would take a count_if(condition) function over filtering and then taking the length.