6 ms·
> though I'm not sure they have precise definitions Of course they don't. These "paradigms" like OOP or FP are just human made up terms _without any basis in t
by sideeffffect 4y ago
> though I'm not sure they have precise definitions
Of course they don't. These "paradigms" like OOP or FP are just human made up terms _without any basis in theory_. Sometimes they can be practically useful when communicating with other humans, like we do now. But more and more people are starting to realize how meaningless/nonsensical these categorizations are (and always have been): FP vs OOP, compiled vs interpreted, static vs dynamic, etc. We might as well categorize languages based on the colour of their mascot.
See this for more https://old.reddit.com/r/ProgrammingLanguages/duplicates/6xtg3e/what_if_anything_is_a_programming_paradigm_robert/ https://old.reddit.com/r/ProgrammingLanguages/duplicates/6xt...
The closest thing to the definition of an FP language that I was able to come up with is "based on the Lambda calculus". Haskell is, Scheme is, F# is. But e.g. Scala isn't, it's fundamental building block isn't functions but objects. But many people do consider Scala to be an FP language.
So let's all be aware of the limitations of these (pseudo-)concepts.
- valenterry 4y agoThat's not really true. Yeah, the term "FP" has been watered down but there was a proper definition: "FP is whene every expression of a program is referential transparent" and that's it. (https://en.wikipedia.org/wiki/Referential_transparency https://en.wikipedia.org/wiki/Referential_transparency) In other words, this is not even a property of a programming language. It is a property of the code itself. It's just that some languages make it easy or impossible to build a program in that style - or they even enforce it. Haskell however has escape hatches. And Scala is considered an FP language because, unlike Javascript/Lisp/Clojure/ML/Rust/... it really allows and supports(!) to make the whole program referential transparent.
- kaba0 4y agoJava is referentially transparent. It just really doesn’t mean what you believe it does. It means that one can replace a reference to a thing with the thing itself. It is a syntax level term, muddying execution model is just not correct usage, see https://stackoverflow.com/questions/210835/what-is-referential-transparency https://stackoverflow.com/questions/210835/what-is-referenti... What you are looking for is simply and plainly “pureness”.
- valenterry 4y ago> Java is referentially transparent Referential transparency is not a property of programming languages but expressions (or more general, parts of computer programs). > It means that one can replace a reference to a thing with the thing itself. That's not the common definition at all. Read the link I posted. In any case, I'm talking about evaluatable expressions, you talk about "references" - however you define that. Even in your own stackoverflow link, the accepted answer says this: > the thing that an expression refers to
- kaba0 4y agoBut expressions don’t mean the thing they evaluate to, this is an ad hoc meaning used in FP circles only. Is `fibonacci 1000` the integer value it evaluates to? No, it is an expression denoting the calculation of that value. What’s missing from side-effect freedom or pureness? That is the property that allows replacing an expression with its value.
- valenterry 4y ago> But expressions don’t mean the thing they evaluate to, this is an ad hoc meaning used in FP circles only. Is `fibonacci 1000` the integer value it evaluates to? No, it is an expression denoting the calculation of that value. Not sure what you are talking about now. > What’s missing from side-effect freedom or pureness? That is the property that allows replacing an expression with its value. I think you are just unfamiliar with the terminology, that's all. See Wikpedia again: > If a pure function is called with arguments that cause no side-effects, the result is constant with respect to that argument list (sometimes called referential transparency or idempotence), i.e., calling the pure function again with the same arguments returns the same result. (This can enable caching optimizations such as memoization.) (https://en.wikipedia.org/wiki/Functional_programming#Pure_functions https://en.wikipedia.org/wiki/Functional_programming#Pure_fu...) There you go. All 3 terms in once sentence. Maybe, again, you disagree with Wikipedia and the definition and that's your good right, but I don't see any point in prolonging the discussion over that.
- kazinator 4y agoHow do you define named functions in something that is referentially transparent? Can a function-defining expression be transparently replaced with the value it computes?
- valenterry 4y agoWell, that depends a bit what you mean by "function-defining expression". Let's say `(new function(input) { return input })` is a valid expression. If it then doesn't matter (in any circumstance) whether you do let myFunction = (new function(input) { return input }) myFunction(1) myFunction(2) or (new function(input) { return input })(1) (new function(input) { return input })(2) that's when you can call the function-defining expression to be referentially transparent. If, on the contrary, creating a function increases a counter and you use that counter in your programing for something and it makes your program behave differently depending on how many functions are created, then the function creating expression would cease to be referential transparent. I think that's not a bad example actually, because I assume it feels more natural to people to be able to treat an expression that creates a function in the way above and expecting that it won't change how the program behaves. And this is really what functional programming is about - it is exactly this feeling and guarantee that FP enforces throughout the whole application, not just in some places. If you are talking about creating a named function (i.e. a class member) that is not an expression, then there isn't really much point in talking about it since we are now talking about definitions, not expressions anymore. Unless you can change/create definitions programmatically - in that case the code that does it programmatically is the one that needs to be considered, not the definition itself.
- kazinator 4y agoWhat is the value of let myFunction = ... which can replace that whole construct so that the program remains the same? Or is this not functional?
- valenterry 4y agoI think you are confused. FP doesn't require any kind of token/syntax to be "replacable". It requires expressions to be "replacable" (RT). A language could certainly treat assignments as expressions (some do) and have them return something, such as the value that is assigned to the variable or always null/unit. But we are now talking about a totally different thing.