O'Reilly logo
  • Andrei Korostelev thinks this is interesting:

Recursion should be used over loops wherever possible


Cover of Learning React


Recursion can typically allow you to use other concepts such as immutability. Most loops that are used will be altering a mutable data structure. In functional programming, using an immutable data structure is typically preferable to using a mutable data structure. Using immutable data structures can allow for things like simple parallelizing of your functions, so you can distribute the work among several CPU's without running the risk of corrupting your stateful object, precisely because a stateful object doesn't exist.