30 ms·
Swift and the Legacy of Functional Programming
- jonathanstrange 10y agoYo, would be nice to have some functional programming language with decent syntax to program apple machines. Let's call it Dylan to honor the most recent winner of the Nobel prize for literature. Just kidding. The bottomline of this page and talk is that Swift is still not functional. But you can do cool things with it.
- ubertaco 10y agoI dunno; I think the bottom line of this page is that functional programming is a set of approaches for solving problems, and some of those approaches can be done in Swift.
- macintux 10y agoHaven't read the article yet, but the problem I find with this attitude generally is that the constraints found in FP are what I find valuable, and what are usually missing from languages which support functional approaches.
- seagreen 10y agoWell said. I can write exceedingly low defect code without folds. I can't do so with implicit IO everywhere, ad hoc polymorphism, and dynamic typing.
- speg 10y agoMy take was that you can solve problems by breaking things down. In functional programming you do so with functions. In Swift you can do so with types.
- carapace 10y agohttps://en.wikipedia.org/wiki/Dylan_(programming_language) https://en.wikipedia.org/wiki/Dylan_(programming_language) (for those who didn't get the joke... ;-)
- grabcocque 10y agoAsk five programmers to define functional programming, get fifteen different answers.
- galad87 10y agoSame thing can be said for object-oriented programming, unfortunately.
- greydius 10y agoMost 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.
- gardenhead 10y agoThat's just one aspect of functional programming. By that definition, almost any modern language is functional.
- seanalltogether 10y agoI'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.
- ryanschneider 10y agoPersonally, I prefer the map/filter approach because people is now a let constant, but I work at a startup with people that don't come from a software development background that would have next to no idea what that line even means. So don't forget your code's target audience, I've personally had to back off some of the more functional styling in Swift just so I'm not the only one that can maintain our code base. For that reason, I really wish Swift had list comprehensions, just because it's the first "slightly functional" exposure most non-developers get if they come from Python.
- tekromancr 10y agoI don't think it's THAT difficult to learn to understand functional style programming. I like to think that I would consider trying to show my team mates the joys and positive aspects of functional programming before I just wrote them off, were I in your situation.
- pklausler 10y agolet persons = [ p | n <- names , p <- peopleNamed n , isValid p ] is even better, if your programming language has comprehensions.
- aninhumer 10y agoEh, maybe for more complicated examples, but I think that comprehension is a lot more complicated than: filter isValid (map peopleNamed names)
- zmmmmm 10y agoThere seem to be a lot of "pretend" functional languages around these days. I have recently been engaging with Scala. Having heard and read so much about how it embraces functional style I was kind of shocked to find the number of limitations and practical impediments to actually using it that way. I am starting to wonder if functional programming has finally fallen victim to the same problem that has afflicted all other methodologies - becoming too popular, part of the hype cycle and getting misinterpreted and misapplied everywhere as a consequence.
- lmm 10y agoScala is about as functional as it gets - the only remotely mainstream language that's more so is Haskell, IME. What kind of issues did you have?
- stingraycharles 10y agoThis sounds pretty misinformed. There are plenty of choices in between Scala and Haskell; Clojure and Elixir are two other relatively popular languages that come to mind.
- bad_user 10y agoYou might have fallen victim to misinformation yourself. In general, functional programming in Scala tends to be more FP, with code tending to be more pure than in Clojure and I have no experience with Elixir, but I have some experience with Erlang and FP code in Scala tends to be held at a higher standard than in Erlang. Of course, you've picked 2 dynamic languages as examples and FP in dynamic languages is different than that practiced in static languages like Haskell or Scala. LISP developers for example don't think so much about monads or other abstractions with mathematical foundations, because LISP developers tend to work around such needs by doing macros (which then have composability problems) or by bending the rules a little, or in other words I've seen no LISP to make a serious attempt at reasoning about I/O in a pure way. And IMO code in static languages tends to be more pure because of the types, because by having an expressive type system, the developers then want that type system to explain everything. Or in other words, dynamic languages are cool for your day job, but if you want to actually feel what FP is all about, you're better off going for a static languages like Haskell, or even Scala or OCaml. PS: http://typelevel.org/ http://typelevel.org/
- melling 10y agoThe talk discusses how you can incorporate a few functional techniques (map, filter) but the speaker's main goal seems that he wants Swift to be changed to allow for a couple of other functional ideas to be brought into the language. Where's the Swift proposal for the enhancements? Product and Sum support? Algebraic data types?
- delegate 10y agoI enjoyed the talk, thank you. The part about "lifting" a type was an 'aha' moment for me and now I understand!*. I mean, I did this intuitively, but now I know the name of the technique, which is really good. Thank you, I've learned something new today!