3 ms·
I don't know about ActionScript, but javascript is actually a pretty beautiful language. It's basically scheme with Java syntax. Also, we're stuck with JS for
by jayferd 15y ago
I don't know about ActionScript, but javascript is actually a pretty beautiful language. It's basically scheme with Java syntax.
Also, we're stuck with JS for the time being. PHP is easy to ditch by comparison.
- zbuc 15y agoTry running [] + {}, then {} + [] in a JS interpreter sometime.
- jayferd 15y ago...yeah, it's got its warts (see wtfjs.com), but it's built on a very solid foundation. It does get a bad rap because of the poor (and inconsistent) design of the DOM, but if you play within its rules it can be very expressive and powerful.
- zbuc 15y agoWell, that was a language inconsistency, not an issue with the DOM. I like working with JS but I don't know why the two operands aren't commutative in my example. The DOM is a headache but luckily smart people have made plenty of libraries to abstract that away. What we're left with is a language with a very expressive and powerful core like you said, but there are still some oddities.
- silentOpen 15y agoNo TCO makes it very much not scheme or lisp or anything fp.
- viscanti 15y agoHaving lambda expressions, closures, and being able to construct higher-order functions makes it pretty "functional" in my book. Having to be careful about recursion is a negative, and TCO would be a welcome addition. It's really a hybrid language. You can do a lot functional stuff with it if you'd like. You can also do a lot of the OO thing with it. Neither is perfect, but if you stick to the "good parts", it's a strong language.
- silentOpen 15y agoLambda 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.