4 ms·
Just a note that functional programming here seems to be conflated with declarative programming. They do have some things in common ("no mutable state" being th
by dataflow 4y ago
Just a note that functional programming here seems to be conflated with declarative programming. They do have some things in common ("no mutable state" being the main one I can recall), and technically I think FP is categorized as a subset of DP, but in reality a declarative program ends up looking quite different from a functional program, so it's with distinguishing the two.
To give a trivial example to illustrate the conceptual difference: a declarative program could say something like "the output is the solution to f(x) = 0", defining f explicitly and leaving it to the compiler/interpreter to supply the algorithm for figuring out an x that satisfies it. Note that, as long as x is unique, "try all legal values of x" works, so a viable fallback algorithm always exists; it's just inefficient. Whereas with FP you actually have to supply an explicit function to (hopefully efficiently) compute the output, i.e. you basically have to write f^-1 yourself, which typically results in a very different program - sometimes harder to read, sometimes easier.
Now, of course, you could do "FP" by writing f instead of f^-1 and then enumerating all possible inputs as with DP, just as you could write a DP to compute functions explicitly at every step, and you could write imperative programs for all these. But those would be unnatural, and would generally defeat the advantages of the paradigms.