Comment

Comment by peterthehacker

> After spending years in functional-land, I find the for loop (and while loop) construct maddening; you have to maintain the state of the entire enclosing scope system in your head.

This is only true if immutability is enforced. In js you see map used to mutate variables outside the scope of the map closure all the time.

  const o = {}
  const d = [1, 2, 3, 4]
  d.map(i => o[i] = i**2)
Which is equivalent to this python.

  o = {}
  d = [1, 2, 3, 4]
  for i in d:
    o[i] = i**2
The cognitive load is the same in both. The strength of pure FP languages come from enforced immutability, but that constraint often adds cognitive load in other ways.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton