5 ms·
Man, this article really shows why imperative programming is so much harder to reason about than functional programming. Difference between "variables" in math
by brianberns 10y ago
Man, this article really shows why imperative programming is so much harder to reason about than functional programming.
Difference between "variables" in math vs. functional programming? None. The value of a variable can't change.
Difference between "function" in math vs. functional programming? None. It's just a map from one set to another.
- dualogy 10y agoIncomplete assessment. Functional programming much better supports equational reasoning. Imperative programming much better supports operational reasoning. Or you could contrast "data flow" vs "control flow". I'd have thought we won't need operational reasoning in 2017 but currently I conclude it may always be a part of computer programming..
- komali2 10y agoI don't really know much about functional programming. How can a variable not change?
- dualogy 10y agoConstruct a whole program of functions only with say `readonly` (in c#) or `const` (in EcmaScript) or only `:=` (in Go) "variable" "assignment-declarations", never mutating them after initial declaration. It's possible and it's one of the core tenets of purely FP.
- crimsonalucard 10y agoIn functional programming the entire program is literally a single expression. This is essentially what functional programming is. A variable in a single expression cannot be modified.
- clusmore 10y agoIn mathematics, variables don't change inside expressions -- they define a family of expressions, each with a different value. For example, in the function f(x) = x^2 + x + 1 the value of x in the right-hand-side expression doesn't change in the same sense that variables in imperative languages change. But it allows the single expression "x^2 + x + 1" to have a value which varies by the value of x. For example, f(2) yields the value 7 while f(3) yields the value 13.
- khedoros1 10y agoYou've described the reason that I doubt I'll ever do much with functional programming. Using it to solve a non-trivial problem reminds me unpleasantly of math, rather than lists of instructions.
- dreamcompiler 10y agoThis is what I like about FP. As in math, you're expressing ideas about relationships that must always hold true, regardless of time. You think less about how state changes over time and more about what the fundamental "truths" of your program have to be. For me -- and for many problems but certainly not all -- this is an easier way to think.
- dualogy 10y agoyeah "regardless of time and space", as one observes in the resulting time and space usage. By the time the purely functional program has been tweaked for better (time and space) performance, said readability has greatly suffered ;D and I say that as an enthusiastic FPer
- eikenberry 10y agoWhat evidence is there that math is easier to reason about than imperative programming?
- brianberns 10y agoHere's an article that explains it pretty well: http://fsharpforfunandprofit.com/posts/is-your-language-unreasonable/ http://fsharpforfunandprofit.com/posts/is-your-language-unre...