7 ms·
> Why is the gap between these two perspectives so large? My conclusion is that there are major, well-justified reasons for why people strongly dislike function
by lolinder 4y ago
> Why is the gap between these two perspectives so large? My conclusion is that there are major, well-justified reasons for why people strongly dislike functional languages.
Now that (nearly) every mainstream language has lambda expressions, there are very few patterns in functional programming that cannot be replicated in mainstream languages, which means that moving to a pure functional language now provides strictly fewer choices when problem solving. In order for a programmer to accept a language with strictly less expressive power, those new restrictions must solve problems that the programmer actually cares about.
Rust reached adoption because mainstream systems programmers recognized that memory errors are a huge problem and dealing with the borrow checker is worth it to solve them. Static typing reached mainstream adoption because it made coordinating work in a large team dramatically easier and solved refactoring.
Functional-style programming has hit the mainstream—embedded within imperative and OO code—but purely functional languages have yet to make a good case for their additional restrictions, and I'm not convinced that multiprocessing is that case. Golang mainstreamed a very effective model for multiprocessing in an imperative environment that solves most of the problems without asking programmers to completely change the way they write code, and that model is increasingly being adopted in other languages (Java's project loom, for example).
- amitport 4y agoI would credit this model for multiprocessing to LISP family (Scheme/Rackt/Clojure) before golang. (Probably someone else would mention an earlier references :)
- lolinder 4y agoYep, there's a reason why I credited Golang with mainstreaming the concept, not inventing it. The model goes back quite a ways, but Golang brought it into the mainstream.
- noelwelsh 4y ago> Now that (nearly) every mainstream language has lambda expressions, there are very few patterns in functional programming that cannot be replicated in mainstream languages I don't think this is true. Algebraic data types and exhaustive pattern matching, which implies a type system, are the things I use most in my adventures in functional programming. Mainstream languages (for some definition of mainstream) don't yet have these features. The original post doesn't mention pure FP. I don't think purity is that interesting when you can have a type system that can reason about mutation (i.e. linear or affine types, similar to Rust.)
- lolinder 4y agoKotlin and Java now have sealed classes/interfaces, which can provide exhaustive pattern matching and as far as I can tell can be used to model any ADT. EDIT: In fact, both languages are now listed as having ADTs on the Wikipedia page: https://en.m.wikipedia.org/wiki/Algebraic_data_type https://en.m.wikipedia.org/wiki/Algebraic_data_type Also, TypeScript's union types can express ADTs, and Rust's enums. I don't think it will be very long before the rest of the mainstream languages catch up.
- noelwelsh 4y agoAgreed, but that's why I hedged with "some definition of mainstream". I don't think Kotlin or Rust are mainstream yet, most Java places are still on Java 8 or 11, and ADTs in Typescript are a PITA.
- kaba0 4y agoI wouldn’t be surprised if there would be more people on Java 19 than on Haskell, for what it’s worth.
- wk_end 4y agoADT's in TypeScript aren't as nice as in a language that supports them natively in many respects, but "PITA" is really overselling it. We use them pervasively at my shop. In fact, the ability to synthesize them without naming them (because TypeScript is structurally-typed instead of nominally) sometimes makes them even more convenient than in most FP languages (OCaml excepted) - the ability to, say, return an ad-hoc ADT from a lambda without giving it some meaningless name like "HelperFunctionResult" can occasionally be really handy.
- nerdponx 4y agoIt's also a matter of performance. Functional non-mutating patterns in JavaScript and Python can be substantially, sometimes catastrophically, less performant than the procedural/imperative mutating equivalents. All functional programming languages that I know of which have decent performance rely on an optimizing compiler to some extent, and/or core data structures that have been optimized for immutability.
- tikhonj 4y ago> In order for a programmer to accept a language with strictly less expressive power Sort of hard to reconcile this view with just how much more expressive the Haskells and Lisps of the world are compared to Go and Python! I've used all of these extensively and functional languages have consistently let me define more general and flexible abstractions, do a better job of reflecting my conceptual model of the domain in my code... all in substantially less code and less boilerplate (excessive imports aside :P) than primarily imperative languages. Functional languages don't stop you from writing imperative code, they allow you to write code that isn't—and, either way, that's just one small aspect of what makes a language adaptable and flexible.
- lolinder 4y agoLISP isn't a pure functional language, it's a multi-paradigm language that is as dynamic as they come. Its problem isn't lack of expressivity, it's probably that it's too flexible (and of course the syntax throws people off). As for Haskell, I guess that gets into the question of how you define expressivity, which is admittedly a very fuzzy term. Here I meant it to mean capable of fluently expressing many different kinds of algorithms without having to resort to circumlocution. Functional programming is natively supported in almost all modern languages. You call a function which calls a function which calls a function which calls a function, return the result. There's no syntactic sugar, just function calls. In Haskell, while I've seen people argue that do notation may as well be imperative code, it isn't. It's an approximation of imperative code using Church—Turing and a liberal dose of syntactic sugar, and using it effectively still requires you to understand the underlying monadic model.
- CrimsonCape 4y agoThis seems like an easy fix, re-release LISP with cleaner syntax. Lexers have come so far this seems like an easy fix. I can't say i've ever read the opinion that LISP's syntax allows more expressive programming; rather LISP itself allows more expressive programming at the tradeoff of the syntax.
- 4y ago
- karmakaze 4y ago> strictly less expressive power We have a difference in what we consider expressive. How in this more expressive language would you represent pure functions or deeply immutable datastructures if it only offered flexible/mutable ones? More flexible does not mean more expressive. If by expressive you mean conciseness, "Comparing the Same Project in Rust, Haskell, C++, Python, Scala and OCaml"[0] is of interest. [0] https://news.ycombinator.com/item?id=20192645 https://news.ycombinator.com/item?id=20192645
- lolinder 4y ago> How in this more expressive language would you represent pure functions or deeply immutable datastructures if it only offered flexible/mutable ones With a function that doesn't cause any mutations and a set of classes/interfaces that offer no mutator methods. My point is that you don't need to be able to have the compiler enforce constraints in order to express an algorithm—you just write the code. Having the compiler enforce constraints is often helpful but comes with decreased ability to express other types of algorithms that rely on breaking those constraints, so the language as a whole is less expressive. In order for a programmer to accept those limitations there need to be clear advantages, and the advantages that functional programming proponents have put forward so far haven't been persuasive to most developers. By the definition I'm working with, the most expressive languages are the ones that offer the fewest constraints to what the code can do—LISP would be a top contender. Expressivity isn't the highest virtue, but it is valuable and programmers don't give it up unless they can be persuaded it will be worth it.
- karmakaze 4y ago> you don't need to be able to have the compiler enforce constraints Expressing such constraints and having the language/compiler enforce them is part of what I want from an expressive language. That way once I've expressed them, I don't have to ensure those things repeatedly for the entire lifecycle of the program. We each have our definitions and values.
- lolinder 4y ago
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- bcrosby95 4y agoI'm a bit confused, because I don't see the commonality between Go and Project Loom other than lightweight threading. Go's whole concurrency model is still fundamentally different from Java as it went all in on CSP, and Project Loom isn't. Beyond that, nothing about Project Loom fundamentally changes the design of all but the most performance sensitive concurrent programs in Java. For most of us plain programmers that Go was targeted at anyways, a bucket of OS threads is just fine. Now they will be a bucket of virtual threads, which will be nicer, but not exactly game changing.
- sriram_malhar 4y agoGo didn’t really go all in on CSP. It provides primitives for shared memory concurrency as well, in addition to message passing. And if you have messages that are not fully immutable, the producer and consumer have to use mutexes to avoid inconsistency. No different from Loom. What it does better than Loom is that all system APIs are savvy about goroutine yielding
- kaba0 4y agoGo solves no correctness problem regarding parallelism, it is as chock full of foot guns as any other multithreaded largely imperative language.
- initplus 4y agoAny programming language represents limitations placed on the underlying expressiveness of the hardware. By this argument raw x86 asm is "more expressive" than any higher level language. The whole point of a programming language is to provide you with common patterns/designs to simplify reasoning about your program. Even base concepts like a "function" or "struct" is really a limitation on the underlying expressive power. Immutability/purity does solve real problems for programmers: it means that you only have to reason about mutability at the margins of your application. I think people who don't have experience with functional style don't realise how helpful this is. I choose to use functional languages because it makes me a better developer - I am able to write code that I am not diligent/smart/disciplined enough to write in an imperative style.
- lolinder 4y agoI agree completely about immutability and purity—for my own code I strongly lean that way and try to outsource as much of my thinking to the compiler as possible. However, there are times where impurity and mutability are beneficial—whether within a single function or at the margins. Functional programming languages do not tend to have good support for these cases, because their whole thing is representing everything in a functional style. I think this is why functional languages don't tend to get traction while the multi-paradigm languages do. Given a choice between purity and pragmatism, most engineers will pick pragmatism. The alternative is to intentionally remove tools from your toolbox, and unless those tools are demonstrably more dangerous than they are helpful that's a tough sell. My ideal language is a multi paradigm language which has robust, statically analyzable support for objects, imperative code, and functional code.
- Tainnor 4y agoI mean, you can write mutable code in Haskell, too. Parts of it can even look quite imperative. I think there are other cultural problems with the language, though.
- lelanthran 4y ago> I think this is why functional languages don't tend to get traction while the multi-paradigm languages do. Given a choice between purity and pragmatism, most engineers will pick pragmatism. Well, it's obvious to the working corporate-employed programmer, not so obvious to the ivory-tower theorist. The short argument is that the entire point of a program is to take inputs and produce outputs. Making the consumption of inputs and the generation of outputs a second-class citizen in the language with the goal of "purity" just makes it that much harder for a program to perform its primary task.
- lambdasquirrel 4y agoThe fundamental difference between FP and imperative/OO is that in FP, equality is easy, state is hard. In imperative and OO, the opposite is true. The restrictions that are in FP are there because it comes from the standpoint that equality should be easy. In a parallel paradigm, state is hard, period. You look at how people use Spark, for example, and it's kind of funny that they are effectively doing FP using an imperative language.
- pmarreck 4y ago> there are very few patterns in functional programming that cannot be replicated in mainstream languages Well, off the top of my head, the only language that can do something like Phoenix Framework's "LiveView" is... Elixir (and by association, Erlang/OTP underneath), and... that's it, to my knowledge, because of these reasons: https://news.ycombinator.com/item?id=35026508 https://news.ycombinator.com/item?id=35026508
- weatherlight 4y agoFunctional programming boils down to 2 important ideas. 1) Referential Transparency - Basically, you can take an expression in your program, and replace it with the result of that expression. and your program will run the same, every time. 2) Immutability - the idea that data cannot be deleted or changed. Having a language/runtime that truly embodies these two principles completely eliminates entire classes of problems in regards to parallelism and concurrency. Some languages and their implementations are very ergonomic to programming in a FP style, some are not. ( Im looking at every imperative lang that has lambda semantics and now says they are FP. ) I think people get hemmed up talking about what FP is. There's nothing in there, though about Category Theory, Algebraic Data Types, Static or Dynamic Typing Disciplines, etc.
- sa46 4y ago> I think people get hemmed up talking about what FP is You've defined purely functional programming, which seems to be the increasingly common meaning of FP. The original definitions only explicitly refer to constructing programs by combining functions: A History of Lisp http://jmc.stanford.edu/articles/lisp/lisp.pdf http://jmc.stanford.edu/articles/lisp/lisp.pdf > LISP is characterized by [...] composition of functions as a tool for forming more complex functions. Can programming be liberated from the von Neumann style? https://dl.acm.org/doi/pdf/10.1145/359576.359579 https://dl.acm.org/doi/pdf/10.1145/359576.359579 > informal description of a class of simple applicative programming systems called functional programming (FP) systems, in which "programs" are simply functions without variables. However, Backus defines his functional programming system mathematically, which could reasonably be construed as referentially transparent.
- weatherlight 4y agohttps://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf First mention of "Functional Programming" is in the paper, "The next 700 Languages" from July 1965. It's heavily implied that FP is programming with things that resemble mathematical objects and have the above properties, not merely just programming with "functions" so to speak. https://youtu.be/1_Eg8KYq2iQ?t=1230 https://youtu.be/1_Eg8KYq2iQ?t=1230 <- Great talk on what FP programming style is.
- naasking 4y ago> Now that (nearly) every mainstream language has lambda expressions, there are very few patterns in functional programming that cannot be replicated in mainstream languages, which means that moving to a pure functional language now provides strictly fewer choices when problem solving Those patterns in functional programming compose cleanly. They do not compose cleanly once you introduce imperative constructs, which is what you get if all you've done is important lambdas to your OO language, so you've presented a bit of a false choice. All you have is some surface semantics of FP but none of the deep reuse and top to bottom clean, understandable semantics.
- neilparikh 4y ago> provides strictly fewer choices when problem solving. If you view programming as trying to avoid writing the "wrong" program from the state space of all programs, this is a good thing. I guess it's a matter of priorities/viewpoints: whether your goal is to make writing the correct program easier, or make writing incorrect programs harder.