Remix.run Logo
amluto 12 hours 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.

calebh 11 hours ago | parent | next [-]

In 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 10 hours ago | parent | prev | next [-]

Flix 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/

Philpax 12 hours ago | parent | prev | next [-]

Does Rust not meet that description?

amluto 12 hours ago | parent [-]

Rust 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.

Mond_ 11 hours ago | parent | next [-]

Considering 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).

IshKebab 11 hours ago | parent | prev [-]

Yeah 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...

12 hours ago | parent | prev | next [-]
[deleted]
delta_p_delta_x 12 hours ago | parent | prev [-]

> I wish there was a mainstream, high performance language that made both styles equally ergonomic.

Unironically, C++.

Mond_ 11 hours ago | parent | next [-]

> > I wish there was a mainstream, high performance language that made both styles equally ergonomic.

> Unironically, C++.

At best C++ falls under "equally unergonomic".

ndriscoll 12 hours ago | parent | prev [-]

Or depending on what "high performance" means (e.g. if Java or Go would be considered acceptable), Scala.