5 ms·
Javascript is the functional programming community's secret weapon! Sure ES6 will add classes, but they're just syntactic sugar. Wrappers around the truly funct
by AlexanderDhoore 13y ago
Javascript is the functional programming community's secret weapon! Sure ES6 will add classes, but they're just syntactic sugar. Wrappers around the truly functional language underneath. Everyone is slowly being soothed into using a lisp. And when you realise this, it's the funniest thing to watch!
- agentultra 13y agoI'd be hard-pressed to call Javascript a "functional programming language" (whatever that means). Common Lisp also suffers from the same misguided label. In truth we love to mutate state in CL and find lattices of type hierarchies to be burdensome (but a great pool of research for your post-doc). Scheme is about as close as I'll get to pure-FP languages. I don't seem ES6 going down the "purity," route. And I hope it stays far from the border. What I was originally referring to though is (if I recall the history of the language) the roots of Javascript -- that it purportedly was a Scheme-like language before becoming what it is today. And by being what it is now has lagged behind in feature-parity to what programmers are used to in other languages whose history isn't tied to the venerable web browser. It just seems to me from the interviews that skirt the topic that Mr. Eich is finally coming back around to introduce what should have been there from the start. (Updated for clarity)
- AlexanderDhoore 13y agoOf course, it's not Haskell... I'm very aware that Javascript was inspired by Scheme. The lexical scoping for example, is obviously "functional" (indeed, whatever that means). Now they are introducing ways to more easily work with lists. Only thing missing is tail call optimization!
- coldtea 13y ago>I'm very aware that Javascript was inspired by Scheme. The lexical scoping for example, is obviously "functional" (indeed, whatever that means). No it wasn't. That's an urban legend. Eich WANTED to make a Scheme for the browser -- he didn't get a permission to do it, and made Javascript instead, which is actually inspired from other languages like Self. Nothing functional about Javascript's horribly broken scoping either... http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt-scheme/ http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt...
- MatthewPhillips 13y agoYou could use const all over the place.
- AlexanderDhoore 13y agoStill doesn't give you immutable data structures though. For example: const myArray = [42]; myArray.push("Oh noes"); [42, "Oh noes"]
- MatthewPhillips 13y agoUgh, you're kidding? EDIT: checked in Node, yep. That's unfortunate. Can we get a let foo immutable = [1]; or something? EDIT2: Although this can be implemented in user-land with Object.freeze. Create a function that returns a const that is frozen if it is non-primitive. That should cover it, right?
- kevingadd 13y agofreeze/seal don't actually provide true immutability in JS. There are cases where a frozen object can still be modified (Date is one of them, IIRC typed arrays are another)
- tensor 13y agoClojureScript provides truly immutable data structures that compile down to javascript. You can use them from JS: https://github.com/swannodette/mori https://github.com/swannodette/mori
- coldtea 13y agoThere's nothing "trully functional" about Javascript. There's not some secret functional language waiting to get out, any more that it is in any other language with first class functions, from Ruby to C#. http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt-scheme/ http://journal.stuffwithstuff.com/2013/07/18/javascript-isnt...
- ajuc 13y agoJavascript isn't functional like Clojure or Haskell ("no side effects"). But it certainly is similar to common LISP regarding frequent use of higher order functions and closures. Some people call that "functional". Language is more than syntax and set of features. How most people use it is very important, because you will have to interface with others people code, and your code will be interfaced with. Javascript discourages OO programming because of pathological object creation syntax and unusual inheritance model. In javascript APIs you usually pass literals of a few common types and functions. In C# you pass instances of custom classes. The former is more suited for functional programming than the latter. In javascript you use closures for encapsulation, in C# you use private members. I don't think I've ever seen "XManager" class in javascript :)