4 ms·
I was taught in university that functional programming means using functions as first-class-values, so function can get other function as a parameter. That's al
by vbezhenar 9y ago
I was taught in university that functional programming means using functions as first-class-values, so function can get other function as a parameter. That's all. You can write functional code with assembler if you want. Immutability is just another design choice with its pros and cons.
- Asooka 9y agoNot sure why you're downvoted. That's literally the way I learned it first, too. Functional <=> "can use functions as values".
- mbrock 9y agoFunctional programming is also a family resemblance thing: you can't necessarily give a strict definition, any more than you can define "blues music". I'd say functional programming is a tradition that draws from sources like denotational semantics, lambda calculus, Church, Landin, etc etc. There are some different subspecies of functional programming: the Lisp family that draws from AI engineering, MIT, Emacs, actor research via Scheme, etc; the ML family that draws from typed lambda calculus, inductive definitions, and logical proof systems; and more, like concatenative languages. JavaScript was always inspired by functional programming, as evident by Eich's claim to have tried to sneak in a variant of Scheme dressed up as Java. I always use lots of anonymous functions, higher order functions, and nonmutating transformations in my JS, without using any special immutability libraries, and I'm pretty happy with it.
- Dzugaru 9y agoI've always thought that functional programming is about structuring your program in functions and their composition (as opposed to classes) - nothing to do with immutability either. As for JS, I've read "Javascript: The good parts" one day and realized that I can do everything I want using just functions and closures - it's really elegant imo. (even use this approach in Python sometimes)
- deleted 9y ago[deleted]
- cies 9y ago> using functions as first-class-values This is called higher order functions (HOF). FP is a --in my humble opinion-- broader topic describes a certain programming style. HOF is one thing in there, but so are "function+data rather then classes" and "favor immutability". In contrast the imperative programming style is not merely about "not having HOF" or "mutable variables all over the place".
- mannykannot 9y agoThe immutability comes in with the definition of 'function', which, in some circles, means something more specific than an arbitrary unit of code that is callable and which may or may not return a value. While neither 'function' nor 'functional programming' can be used in computing with any precision unless they are qualified, there is a distinct paradigm in which functions have no side-effects and are the only mechanism of elaboration.
- _lce0 9y agoMathematically a Function is a Relation that has two special properties: uniqueness and existence. (these properties names can be wrong as I've not study calculus in English) So on the machine, Immutability plays an important role on the first piece, uniqueness, so it tries to guarantee that results are not just "equal objects, but different instances", which breaks the function definition. Of course that functions that return a new object for the same arguments, even if it's immutable, are not true math functions.
- mcphage 9y agoMathematical functions aren't too great a metaphor for computer functions. They share a lot of similarities—domain, range, inputs, outputs, composability. But mathematical functions just are, there's no notion of changing things—however, the most common purpose of computer software is to change things. So it breaks down, or you come up with some way of defining a change without anything changing, which adds a layer of abstraction to everything you try and do.
- mannykannot 9y agoI think it is correct to say that, in the functional paradigm, you effect change by making something new (and forgetting some older things.) Regardless of the paradigm (other than self-modifying code, perhaps) programs just are, but they must be evaluated if they are to do something useful. I will leave that last sentence as I wrote it, but it immediately leads me to wonder if functions that write functions have wandered into the self-modifying code realm?