2 ms·
If you want to be a C programmer, you need to learn how pointers work. If you want to be a C++ programmer, you need to learn STL and templates. Java, Python, ev
by krapp 8y ago
If you want to be a C programmer, you need to learn how pointers work. If you want to be a C++ programmer, you need to learn STL and templates. Java, Python, every language has its idioms. Javascript is no exception ... it's a simple, untyped language that only has floats, uses prototypal inheritance and, yes, "this." These aren't bugs, they're features.
The web would be a better place if Javascript developers put all of their effort trying to write code in the language they would rather be using into writing better code in the language they are using.
- weberc2 8y agoSo what’s your point? People should shut up and stop wanting to improve things? > The web would be a better place if Javascript developers put all of their effort trying to write code in the language they would rather be using into writing better code in the language they are using. Right, but then no one would use “this”...
- krapp 8y agoIgnoring or avoiding "this" isn't improving things... learning how "this" works and using it properly is improving things. Not wasting effort trying to make Javascript act like more of a functional language than it is would probably reduce the complexity and increase the efficiency of a lot of the code on the web.
- weberc2 8y agoJavaScript was a functional language from the beginning. OOP features were racked on for marketing reasons (Java was popular at the time). “This” isn’t inherently more efficient than programming in a functional style.
- krapp 8y ago>This” isn’t inherently more efficient than programming in a functional style. It is, because avoiding it requires extra and unnecessary abstractions. "this" is a fundamental part of the language regardless of the paradigm. If you want to use a functional style in javascript, you have to accept that it isn't a pure functional language, and do so using "this," not avoiding it.
- weberc2 8y agoThat’s silly. “this” and other OOP features _are_ runtime abstractions built atop a more functional core. > If you want to use a functional style in javascript, you have to accept that it isn't a pure functional language, and do so using "this," not avoiding it. This is nonsense. You don’t have to do anything at all to program in a functional style in JS. You don’t need to use “this” and I can’t even imagine how using “this” would be helpful to that end.
- krapp 8y ago>This is nonsense. You don’t have to do anything at all to program in a functional style in JS. You don’t need to use “this” and I can’t even imagine how using “this” would be helpful to that end. I mean, the premise of the posted article is that javascript developers should avoid using "this" for functional (and OOP) programming, but OK... I can't tell if you disagree with me here, or the author, or what.
- harimau777 8y agoI think the problem is that people often do not have a choice what language they use at their job so the only choice is making the language work the way they want it to.
- alangpierce 8y agoSeems like maybe there's a balance here. On one hand, JS was designed with a particular vision (prototypal inheritance, etc.) and it's good for programmers to understand and follow that vision. On the other hand, even JS experts admit that there are plenty of warts and legacy oddities in JS, and we'd do a lot of things differently if designing the language from scratch. I guess it's unclear where `this` fits in. It's closely tied to the nice elegance of the language, but it's also a huge source of beginner-unfriendliness. IMO it could at the very least have some ease-of-use improvements. JS has gone through lots of careful language changes (strict mode, arrow functions, classes), and tools like ESLint and TypeScript help limit confusing parts of the language, and I think it's worthwhile to put at least some effort into making JavaScript better rather than just accepting it.
- krapp 8y agoFair enough, but I don't think avoiding "this" altogether in order to pretend Javascript is only a functional and not also a prototypal language helps. Doing so is just going to make the language more confusing than it really is.