3 ms·
Also: avoidance of mutable state, even locally. A lot of functions can be more straightforwardly expressed using mutable variables and data structures, and most
by amluto 1y ago
Also: avoidance of mutable state, even locally. A lot of functions can be more straightforwardly expressed using mutable variables and data structures, and most functional languages can handle local mutable state, but a lot of code in functional languages avoids it.
Conversely, a lot of code written in imperative languages would be clearer and/or less bug-prone if it avoided mutable state and used persistent data structures.
I wish there was a mainstream, high performance language that made both styles equally ergonomic.
- deleted 1y ago[deleted]
- delta_p_delta_x 1y ago> I wish there was a mainstream, high performance language that made both styles equally ergonomic. Unironically, C++.
- ndriscoll 1y agoOr depending on what "high performance" means (e.g. if Java or Go would be considered acceptable), Scala.
- Mond_ 1y ago> > I wish there was a mainstream, high performance language that made both styles equally ergonomic. > Unironically, C++. At best C++ falls under "equally unergonomic".
- Philpax 1y agoDoes Rust not meet that description?
- amluto 1y agoRust is very good at making things immutable. But that doesn't mean it's particularly fun to, for example, append or prepend something to a list and retain a reference to both the old and the new list. Compare to most "functional" languages, in which prepending an item to a list and ending up with immutable references to the old and new lists is almost the defining feature of the language.
- IshKebab 1y agoYeah although I find FP languages' obsession with singly linked lists to be a real flaw because they have such awful performance characteristics. And also pretty bad ergonomics often. The number of times stuff comes out backwards...
- Mond_ 1y agoConsidering the performance implications of a full commitment to immutable data structures, I think Rust does a pretty good job here. Dynamic arrays / vectors / slices or whatever you want to call them are probably the most important or fundamental non-plain-old-data data structure, and in a purely immutable environment these are essentially impossible (or have awful performance characteristics).
- calebh 1y agoIn my experience the main benefit of functional programming is function purity. I am completely fine with mutation inside of a function since the all of the mutation logic is self-contained in a single small block of text. I think everyone should take a shot at writing a non-trivial functional program to see the benefit. Once you understand what makes it great, you can apply what you've learned to the majority of OOP/impure languages.
- brabel 1y agoFlix has "regions", which are a way to allow mutation locally while keeping the language purely functional otherwise: See Region-based Local Mutation in https://flix.dev/ https://flix.dev/