4 ms·
I am not pleased at seeing language bloat. Look at what happened with C++11. Languages are supposed to give a common base for developers to read and write the s
by EGreg 13y ago
I am not pleased at seeing language bloat. Look at what happened with C++11. Languages are supposed to give a common base for developers to read and write the same code. New developers should be able to get up to speed quickly, and see the intent of the other developers, which is one of the reasons Linux is written in C instead of C++.
"Look at all that saved typing!"
Yeah, shockingly there were only a few characters saved. And yet the mental overhead of a whole new syntax is introduced, which developers can now encounter in the wild.
"The real benefit of course is that you don’t have to go through the mental hoop-jumping of trying to figure out what scope your function is going to run in (and more often-than-not, you just wanted it to run inside the current scope the function is being defined in anyway)."
The amount of mental hoop-jumping recalling more language features and what they do outweighs this. I can understand if something is really used all the time. But when something is already a pattern that's pretty straightforward to type, do we really need another lexical element, which differs in obscure semantic details like "you can't override the this variable" and other things?
I would argue that languages which are "easy to learn, tough to master", like Chess, are best for programming large projects.
- Fauntleroy 13y agoLet's also note that even though "=>" contains fewer characters than "function", it is arguably more difficult to type, since it requires a jump to the top row of keys for "=", and the shift key for ">".
- ebiester 13y agoI think that => is going to be used far more than you think. The original scoping rules for javascript have caused all sorts of confusion. The important piece isn't removing function, it's removing .bind(this). The changes in ES6 go a long way in making modern javascript more intuitive to write.
- hyperpape 13y agoI agree that the way scope works in fat arrow functions is better, and I'm honestly excited about most of ES6 (proper maps and sets alone are worth it to me). What does make me sad is that the old shit isn't going away. And not that it's not going away soon, but that, as far as we can tell, we're going to be teaching people about "this" for the rest of eternity. I get why Brendan Eich and others are scared of versioning javascript, but I don't think it's tenable to have to keep so many semantically dischordant features of the language around for decades.
- vectorjohn 13y agoYeah, I am really having a hard time seeing what the fat arrow syntax even changes. Everyone keeps saying scope, but the scope is and always has been lexical, right? That isn't changed. All that seems to be changed is what "this" is. So we got a whole new syntax for locking the value of "this". I agree, that does not seem worth it. There are no mental hoops to see that in "self.foo()", "self" was defined 5 lines up.
- rybosome 13y agoI understand your sentiment in general, but disagree in this particular case. I've been writing JavaScript for years in various projects, companies, partnerships, etc. If I had a nickel for every time I saw... asyncOperation(_.bind(function(x) { this.x += x; }, this)); or... asyncOperation(goog.bind(function(x) { this.x += x; }, this)); or... asyncOperation(function(x) { this.x += x; }.bind(this)); or... asyncOperation($.proxy(function(x) { this.x += x; }, this)); or even... var self = this; asyncOperation(function(x) { self.x += x; }); ...then I'd have a lot of nickels. Binding a function to the current scope is _insanely_ common - adding syntax specifically for it makes sense. I would argue that it reduces the cognitive overhead of the language, since rather than needing to read another method call, examine arguments, etc. I can simply translate a 2-character symbol into the meaning "outer-context-bound function". There's a lot more bloat in the above examples than there is in this: asyncOperation((x) => { this.x += x; }); This is like arguing that the '+' operator bloats the language, when we could all just be using Number(17).plus(Number(43));
- EGreg 13y agoWell, in this particular case I agree. If an operation is very commonly used, and/or it can allow major compiler/interpreter optimizations by doing it at the language-level instead of a library level, then you should put it into the language. But this is not the case for SO MANY constructs. Especially in a language like PHP, where they've recently added even more stuff that very few people would care about.
- rybosome 13y agoThat's fair. If language developers were willing to deprecate more aggressively, it wouldn't be such a problem...but every hacked-up, shoehorned feature represents a major investment that must be tended to for years.