News for hackers. Stuff that matters.
Re:Swift and the Legacy of Functional Programming by mikeash on Monday November 21, 2016 @02:09PM (#13008170)
I find the first one to be far easier to read. You can basically just read it from top to bottom and know exactly what it does. "Take names, turn each one into a Person, keep the ones that are valid."

The second one takes a lot more work. First, I have to read through the code and recognize that this is a loop that accumulates values into a new array. Then I have to pick it apart and see exactly where the accumulation takes place, and how that value is derived. It's not hard by any means, but the first one is far more straightforward.

Re:Swift and the Legacy of Functional Programming by skizm on Monday November 21, 2016 @03:21PM (#13008812)
Is the first one two loops or one?
Re:Swift and the Legacy of Functional Programming by mikeash on Monday November 21, 2016 @04:02PM (#13009187)
Two. These methods are not lazy by default. Of course, you have to know the language pretty well to know that, but I do. For anyone wondering, you can write names.lazy.map(...) to get lazy evaluation.
Re:Swift and the Legacy of Functional Programming by chii on Monday November 21, 2016 @08:16PM (#13010827)
The real answer is that it doesn't matter. Just like for most code, the output assembly or machine code doesn't matter.
Re:Swift and the Legacy of Functional Programming by actsasbuffoon on Monday November 21, 2016 @04:01PM (#13009180)
It depends. Using lazy data structures, transducers, or a number of other common tricks would turn it into one loop. Haskell, Clojure, Ruby, Scala, Swift, and many other languages make it pretty easy to do.
Re:Swift and the Legacy of Functional Programming by andreareina on Tuesday November 22, 2016 @12:35AM (#13011876)
Naïvely, two. The compiler can probably figure out that the semantics are the same and choose depending on what its model says will be faster.