3 ms·
You must have a very particular idea of what "functional" means to include JS. What definition of functional programming does JS meet that you can't apply to ne
by ryeguy 10y ago
You must have a very particular idea of what "functional" means to include JS. What definition of functional programming does JS meet that you can't apply to nearly every language? It can't be that it just has first class functions, lambdas, or higher-order functions: many, many languages have that.
Functional languages emphasize immutability. Javascript does not do this. Clojure[script] does.
- Sanddancer 10y agoIt's functional. It has all the components needed to code in a functional style, but at the same time, lets you use other paradigms, such as OO, when they make the most sense to do so. I'd argue a "pure" functional language is akin to trying to write a novel on a keyboard without an "e" key. Sure, you'll eventually stumble and write "Gadsby", but there are times when being able to cheat is useful in making your code more clear and concise. When I code stuff in C++ or C#, I keep my objects immutable most of the time because it's the easiest way to rationalize the various components that way, but at the same time, when I'm doing things like handling I/O, a pure functional style gets in the way.
- paulddraper 10y ago> What definition of functional programming does JS meet that you can't apply to nearly every language? Since functional programming is a programming paradigm, not a language, don't be surprised if many languages support it, just as many diverse languages support OO. The language support generally thought necessary is first-class functions (and consequently concepts like higher-order functions). For example, Java < 8 and C# < 2.0 aren't usually considered functional. If you think allowed mutability makes or breaks a functional language, then neither Clojure nor Clojurescript fit the definition.
- a-saleh 10y agoI think there are degrees of this. Like, once you have * first class functions that you can pass around * anonymous functions * closures over functions you can get by. This is what enables you to create the usual higher-order function toolbox, all those nice functions that convert your code to long list of composable map/filter/reduce/zip/walk e.t.c. I remember reading that python got here iteratively, i.e. you could pass around functions, but they needed to be defined top-level, then you had anonymous functions, but you needed to pass in variables from enclosing scope explicitly, and finally you had closures. But I agree that fast, immutable datastructures make all of this much nicer. But not having them is not as much of a deal-breaker. Similarily tail-call optimization. I used clojure at work while dealing with haskell on a school projects, and from that time on, I found "loop/recur" kinda ugly :-) NodeJS with --harmony actually supports it now. Similarly, pattern matching. Don't you need to pull that as a lib in clojure as well? With destructuring this almost is a js feature. So, I wouldn't loose much sleep over it anyway :)