3 ms·
Progress has come from making immutability more usable. Many of the troubles in programs come from something mutating state that something else is depending upo
by Animats 8y ago
Progress has come from making immutability more usable. Many of the troubles in programs come from something mutating state that something else is depending upon. This is not really a functional thing.
The important concept is "single assignment". This is where values are initialized at creation and never changed. Go, which is an imperative language, favors single assignment. Functional programming is a form of single assignment.
Single assignment in an imperative syntax has some advantages over a pure functional form. Values have names, which helps when reading code. You can use the same value twice. It's functional programming without the cult.
The downside of single assignment is that you're frantically creating and discarding values. Underneath, the machine is imperative. So you need compiler support for efficient creation and discarding of values. LISP spends a lot of time creating and discarding values, then garbage collecting them. So do Javascript, Python, etc. Vast amounts of effort have gone into making that efficient, and today it's not a big problem. Rust goes even further, handling most of that overhead at compile time.
- antidesitter 8y ago> Single assignment in an imperative syntax has some advantages over a pure functional form. Values have names, which helps when reading code. You can use the same value twice. This is where Haskell’s let <variable> = <expression> in <expression> bindings come in handy.
- aikah 8y ago> Go, which is an imperative language, favors single assignment. Go doesn't even have final variables. Go doesn't favor single assignment in anyway. Rust does as it is harder to create a mutable variable than an immutable one.
- Animats 8y agoGo has "=" and ":=", to distinguish alteration of variables.