Ask five programmers to define functional programming, get fifteen different answers.
Most people would agree that in functional programming we can pass functions around as first class objects. What we disagree on is the definition of function.
Swift and the Legacy of Functional Programming
11–20 of 188 posts
Re: Swift and the Legacy of Functional Programming
#12Ask five programmers to define functional programming, get fifteen different answers.
I always thought FP == pure functions. I guess not?
Re: Swift and the Legacy of Functional Programming
#13Earlier quoted context omitted.
Most people would agree that in functional programming we can pass functions around as first class objects. What we disagree on is the definition of function.
That's just one aspect of functional programming. By that definition, almost any modern language is functional.
Re: Swift and the Legacy of Functional Programming
#14Ask five programmers to define functional programming, get fifteen different answers.
Re: Swift and the Legacy of Functional Programming
#15Ask five programmers to define functional programming, get fifteen different answers.
To me the core is "no side effects" though (for pure FP). It's interesting to see what others consider to be the most salient feature(s).
Re: Swift and the Legacy of Functional Programming
#16 let persons = names
.map(Person.init)
.filter { $0.isValid }
easier to read than this? var persons: [Person] = []
for name in names {
let person = Person(name: name)
if person.isValid {
persons.append(person)
}
}
I understand and appreciate the value of compact code, but I find the first one harder to read. A lot of inferred/token based coding is harder for me to mentally parse.Re: Swift and the Legacy of Functional Programming
#17I'm curious, does every else find this let persons = names .map(Person.init) .filter { $0.isValid } easier to read than this? var persons: [Person] = [] for name in names { let person = Person(name: name) if person.isValid { persons.append(person) } } I understand and appreciate the value of compact code, but I find the first one harder to read. A lot of inferred/token based coding is harder for me to mentally parse.
let persons = [ p | n
is even better, if your programming language has comprehensions.Re: Swift and the Legacy of Functional Programming
#18I'm curious, does every else find this let persons = names .map(Person.init) .filter { $0.isValid } easier to read than this? var persons: [Person] = [] for name in names { let person = Person(name: name) if person.isValid { persons.append(person) } } I understand and appreciate the value of compact code, but I find the first one harder to read. A lot of inferred/token based coding is harder for me to mentally parse.
It also depends on the language obviously. In this example, the first example has special tokens for the filter. It doesn't have to be so.
Re: Swift and the Legacy of Functional Programming
#19I'm curious, does every else find this let persons = names .map(Person.init) .filter { $0.isValid } easier to read than this? var persons: [Person] = [] for name in names { let person = Person(name: name) if person.isValid { persons.append(person) } } I understand and appreciate the value of compact code, but I find the first one harder to read. A lot of inferred/token based coding is harder for me to mentally parse.
When it's optional, well, sadness ensues.
Re: Swift and the Legacy of Functional Programming
#20I'm curious, does every else find this let persons = names .map(Person.init) .filter { $0.isValid } easier to read than this? var persons: [Person] = [] for name in names { let person = Person(name: name) if person.isValid { persons.append(person) } } I understand and appreciate the value of compact code, but I find the first one harder to read. A lot of inferred/token based coding is harder for me to mentally parse.
The other thing is that experience brings the ability to track what's going on. The formulation of the answer here is probably new to you. As you get use to this, or Streams for Java, or threading for Clojure, etc, you'll understand it by default.