4 ms·
> We'll use the world's most popular functional programming language: JavaScript Then you won't be doing functional programming. You will be doing "somewhat fu
by dozzie 11y ago
> We'll use the world's most popular functional programming language: JavaScript
Then you won't be doing functional programming. You will be doing "somewhat
functional programming" at best.
- ExpiredLink 11y agoUndoubtedly, JavaScript triggered the functional hype, not Haskell or Clojure.
- rubiquity 11y agoI would say it's a joint mindshare from all the various functional families (Lisp, ML, Erlang). After all, what kind of programmers do you think wrote the functional libraries that led to the "functional hype" in JS in the first place?
- ExpiredLink 11y agoJavaScript's functional hype was initiated by Douglas Crockford.
- untog 11y agoYou're right, they should have added a caveat: "Anonymous strangers on the internet will tell you that what you're doing isn't "real" functional programming, but hey - at least you'll actually be programming rather than whining on message boards"
- dozzie 11y ago"Of course those random strangers will not know several languages of different paradigms, and will not be programming themselves, in opposite of what you are doing." You know that this doesn't make JavaScript be a functional language, right? It still only has some parts from functional paradigm, and those are not well-fitted, so fully functional programming in JS is awkward.
- taco_emoji 11y agoWhich aspect of the functional programming paradigm cannot be done in Javascript?
- dickson 11y agoTail recursion optimization, lazy evaluation
- sabarjp 11y agoTail recursion optimization is in ES6. Lazy Evaluation is provided in multiple libraries, including lazy.js. There are also several libraries with pure functional implementations (ex: bilby)
- Lazare 11y agoIf you're listing a core language feature as something that "can't be done in that language", you may not understand the language as well as you think.
- Kutta 11y agoPolymorphic return types, most notoriously. But also anything that's complex enough so that dynamically typed implementations become unfeasible or effectively unmaintainable.
- lojack 11y agoIs there a reason why you can't do functional programming in JavaScript. Unless I'm mistaken, there isn't anything about JavaScript that explicitly prevents you from doing functional programming. Even then, I think we all understand that the OP isn't trying to be strictly pure and is simply trying to explain the concepts in a manner that those used to imperative development can easily digest.
- dozzie 11y ago1. No pattern matching. Libraries can't help here, it's a syntactical and semantical issue. 2. No product types. You can emulate those, but it's awkward. 3. No recursion over lists. You can emulate this, but it's awkward. 4. It's difficult to write code that is efficient, yet is side-effects free. Good luck with prepending an element to a list. About emulation, you can emulate closures on Turing machine, though it doesn't make Turing machine a functional language. Lack of the aspect is simply lack of the aspect. And no, JS doesn't explicitly prevent functional programming (or rather, some aspects of it). It does so implicitly. > OP isn't trying to be strictly pure and is simply trying to explain the concepts in a manner that those used to imperative development can easily digest. It's like trying to show how to do OOP in C. It's a different paradigm than the primary of the host language, so any educational aspect will be severly diluted, to the point of being useless to anybody who doesn't already know functional programming.
- dragonwriter 11y ago> No recursion over lists. You can emulate this, but it's awkward. What do you mean by no recursion over lists? I mean, sure, lists aren't a core data type in JS (JS arrays aren't lists), so list operations aren't either, is that it?
- dozzie 11y agoIt's not "is that it". Single-linked lists of specific characteristics (access times, construction times and stuff like that) are one of the few core elements of functional programming.
- 11y ago