3 ms·
Loops can do many things that HOFs cannot. That's an advantage of HOFs; when you see one, you know exactly what it does, compared to loops where anything can h
by orangecat 11y ago
Loops can do many things that HOFs cannot.
That's an advantage of HOFs; when you see one, you know exactly what it does, compared to loops where anything can happen either intentionally or accidentally. It's a form of the principle of least power.
For HOFs, you need a language with closures, and in some cases GC as well. Loops, on the other hand, can be done in C.
C uses HOFs in many places, like the compare function in qsort.
- vanderZwan 11y ago> when you see one, you know exactly what it does, compared to loops where anything can happen either intentionally or accidentally. That is debatable, which is shown by the parent comment decrying the "bewildering zoo" of HOFs. I could flip this argument around and say that for loops have all complexity explicitly written out using fairly simple low-level constructs, whereas with HOFs I have to remember the semantics of each of them. And it would be equally unconvincing.