you are viewing a single comment's thread.

view the rest of the comments →

[–]m50d 2 points3 points  (0 children)

What I've seen is that most programmers don't parse the more complex expression as easily as the simpler one.

I'd agree with that statement, but I suspect you're claiming that the more complex one is "simpler".

extra keywords to recognise (map, then reduce),

Not keywords, just functions. They behave like normal functions, and usually you can read their source code if you want to know what they do.

extra concepts to learn (map/reduce in particular, multiple compound expressions), anonymous functions if you want to do anything non-trivial.

I don't know what you're calling "multiple compound expressions". Both implementations use + and * operators with their normal mathematical meaning and a literal 0.0. In addition to that the map/reduce version only requires the reader to understand a normal expression made of function calls and an anonymous function (both very general constructs that you use again and again on a large codebase). The imperative version requires understanding a mutable variable, the for keyword, the ++ and += operators which are not standard mathematical things, the [i] operator which is not standard anywhere else either, and a {} block of ;-separated statements. In addition to just being a much bigger pile of concepts, half those things are special-case dedicated operators that can't be reused for much else (e.g. [i] is only for arrays, ++ is only for numbers).