4 ms·
In my opinion the most important part of functional programming is the purity of functions. There is a great quote about this on one of the Clojure doc pages "
by RootDynasty 11y ago
In my opinion the most important part of functional programming is the purity of functions. There is a great quote about this on one of the Clojure doc pages
"If a tree falls in the woods, does it make a sound?
If a pure function mutates some local data in order to produce an immutable return value, is that ok?"
Function purity enforces that mutations are localized to small areas of the code, while maintaining composition.
- ufo 11y agoFor me, having first class functions with proper lexical scoping is enough to start feeling functional. That might sound like nothing but its surprising how few of the most popular languages get both of those right.
- Kiro 11y agoWhat is proper lexical scoping? Does JavaScript get it right?
- coldtea 11y agoNo. Javascript gets it horribly wrong without "var", still terribly wrong with "var", and somewhat better with "let".
- Kiro 11y agoI don't understand what let has to do with functional programming though (enclosing a variable within if () {} instead of function block etc). Do you mind elaborating?
- coldtea 11y agoThe question wasn't about functional programming per se, but about lexical scope. "let" keyword in ES6 allows Javascript to have "lexical" style scoping (with some caveats due to JS legacy). That said, several ways of scoping a variable can be had in functional programming. Have a look here for some more explanation with regards to Common Lisp: http://stackoverflow.com/questions/463463/dynamic-and-lexical-variables-in-common-lisp http://stackoverflow.com/questions/463463/dynamic-and-lexica...
- ufo 11y agoThe "this" keyword is also a mess. I wonder when well be able to start using the new arrow-syntax lambdas everywhere.
- ExpiredLink 11y ago> Function purity enforces that mutations are localized to small areas of the code, while maintaining composition. Most programmers of 'traditional' (imperative, oo) programming languages would agree.