1. 6
  1.  

  2. 3

    I’d argue that

    function add (arr) {
      return arr.reduce((prev, current) => prev + current, 0)
    }
    

    While more declarative than looping through the array, is still more imperative than something like arr.sum. Here’s how I define the difference:

    • Imperative Code: Describe strategy, hope computer finds correct result.
    • Declarative Code: Describe result, hope computer finds optimum strategy.

    Note this doesn’t mean that your code is side-effect free. As an extreme example, consider something like next(foo) in Python where foo is an iterator.

    tl;dr everything is fractals

    1. 3

      Those are some pretty good definitions. I think metaphors and code examples are better for teaching new people, though. SQL and HTML vs regular code were good choices by the author. A classic one is Prolog examples with a brief explanation of the backtracking behind the scenes that makes it possible. Author’s was easier to digest than that.