6 ms·
> not picking a functional language As opposed to what? In what ways do you not consider Javascript to a be a functional language?
by ksikka 11y ago
> not picking a functional language
As opposed to what? In what ways do you not consider Javascript to a be a functional language?
- Touche 11y agovar a = 1; a = 2; window.someGlobal = 'foo';
- ksikka 11y agohttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- Touche 11y agoconst a = {b: "foo"}; a.b = "bar";
- dangoor 11y agoconst a = icepick.freeze({b: "foo"}); Granted, that's not as elegant as built-in support but that is literally what I'm doing at the moment when I want immutability.
- Touche 11y agoSo if you go to extraordinary lengths you can use JavaScript functionally but it's not very functional by default aside from the first-class functions. Personally I just embrace it's imperative/functional blended nature and go with it.
- deleted 11y ago[deleted]
- pyrophane 11y agoYea, const provides immutability with respect to assignment, but without immutable objects and collections, it isn't going to get you all the way.
- jsprogrammer 11y agoA functional language can allow mutations (see Haskell, LISP, etc.). All a functional language really needs is first class functions. JS has had that since the very beginning.
- omtanks 11y agoMicrosoft ruined C# by adding var. var is not your friend. Dynamic typing is not your friend and static languages pretending to be dynamic is akin to evil.
- dllthomas 11y agoImplicit typing is not dynamic typing, or even "pretending to be dynamic". It's also, I think, off topic - as the example seemed to be talking about mutability in JS, with no C# for miles.
- fbonetti 11y agoSure, Javascript has first class functions, which I guess meets the bare minimum requirements for being a functional language, but it also lacks some key features: * Pure functions - JS functions are essentially subroutines. They might return a useful value or they might mutate a bunch of stuff and interact with the outside world. Who knows? JS functions aren't guarunteed to return the same value, or any value at all. * Immutability - Anything and everything can be mutated in JS, including the contents of objects that are defined using the new ES6 `const` keyword * Curried functions by default - Although it's possible to compose or partially apply JS functions, it's not nearly as nice as Haskell or Elm.
- klibertp 11y agoYou're influenced by only one part of FP world. Let's take Lisp, or even better: Scheme. * pure functions - all you said is equally true for Scheme * immutability - set-cdr! and many SRFIs: vectors, boxes, records... * curried by default - nope, not in Scheme either There are other flavours of FP languages other than ML descendants. They are not "less functional" at all.
- chc 11y agoIt's true, not every language goes all-in on functional programming — but just because some functional languages are less strongly functional than others, that doesn't mean it makes sense to call every language currently in use a functional language. I mean, it seems pretty useless to define "functional programming language" in a way that includes both C and OCaml just because you can pass functions around in both of them.