3 ms·
Lambda expressions implies currying because lambdas take only a single argument unless you think of function application as implicitly constructing a tuple of a
by silentOpen 15y ago
Lambda expressions implies currying because lambdas take only a single argument unless you think of function application as implicitly constructing a tuple of arguments (but JS lacks tuples and only offers maps and arrays). Javascript has first-class anonymous functions, not lambdas.
Closures in JS are broken due to everything being a reference cell by default. This causes closures to be annoying to construct correctly and more expensive than they should be. "Functional" languages typically treat mutation as a side-effect and require reference cells to be explicitly declared. This helps enforce function purity and referential transparency -- functional-ness.
"Being careful about recursion" is like being careful about looping except recursive expressions are a superset of succinct iterative expressions making Javascript weak when it comes to, say, describing state machines. Lack of TCO makes Javascript a terrible compile target as CPS is impossible.
Javascript is an ambiguous, unsafe, difficult-to-analyze language. It supports some constructs that look like constructs in functional languages but because it does not enforce any functional or type systemic restrictions, these features are mostly cargo.
If you write a recursive algorithm in Javascript, you pay like O(n) for stack frames. The same iterative algorithm costs O(1) for stack frames. Thus, many developers eschew recursion in favor of iteration. This means that the logical code that developers write could be both mathematically sound and run efficiently on the machine but instead developers must either resort to temporal reasoning or perform recursion -> iteration transforms in their heads. This is broken.
Just because Javascript is ubiquitous doesn't mean it's good. I don't understand Javascript evangelists -- they seem to be spreading half-truths.
- viscanti 15y agoI'm not a Javascript evangelist. I'm the first to admit that it has flaws. Some (like recursion) are fundamentally broken and a trap to unknowing programmers. I think you'd be hard pressed to find anyone with any real javascript experience who says the entire language is perfect. There are good parts though, and if you stick with them, it's not bad. In fact, it can be a pleasant experience to work with. Just because it's ubiquitous doesn't mean it's all bad.