7 ms·
Improving some of the syntax was sorely needed but I think adding classes was unhelpful. I already have a hard enough time teaching programmers about prototypi
by ChrisSD 8y ago
Improving some of the syntax was sorely needed but I think adding classes was unhelpful. I already have a hard enough time teaching programmers about prototypical inheritance without the language actively lying to them.
And it feels like an odd move in that class based OOP isn't the zeitgeist it once was. Shoehorning it in feels like a throw back to 90's and 00's.
- scarface74 8y agoThe two most popular statically typed OOP languages for servers are still C# and Java. Besides JavaScript, the most popular scripting language is Python (let’s ignore PHP for now) which is class based. In the mobile space, Swift, Java, and now Kotlin are all class based. “The zeitgeist” is different than “what companies are paying real money for”. Besides, even with OOP based inheritance, the language is still “lying” just as much. Most developers who don’t understand how the lowest level of computers work don’t understand that when you call a function it’s always basically passing in a this pointer to one static instance of the function.
- jerf 8y agoObject orientation in the sense of having some sort of data structure having some officially associated "methods" with it, and then building other structure on top of that, is alive, well, and not going anywhere any time soon despite the occasional functional programmer epiphanies. Object orientation as in "There must be classes, there must be inheritance, each method and instance value must be able to be private, public, or protected, and have official constructors and destructors" and probably a couple of other things I'm missing, is also alive and well and not going anywhere any time soon, but is no longer the only definition of Object Orientation. If you were not around at the time, you'll have to take my word for this, although the echos still reverberate in Javascript tutorials to this day (because of the way they talk about prototype-based inheritance as if you've got to be placated long enough about the fact that it isn't "true" OO long enough to learn what it actually is), but when it was released, Javascript (prior to any sort of "class" keyword) was not considered an "object oriented" language, because it didn't have "real" inheritance, or private values, etc. etc. The point is that in a world where the definition of "OO" has expanded enough to encompass the original JS, it's a bit odd to bodge on a particular definition of OO so late in the process. (People also argued back then about whether Python was object oriented (!), because it didn't have "true" support for private instances or methods. By contrast, I find it amusing when sometimes the question comes up "Is Go really Object Oriented if it has no inheritance?" and the answer generally amounts to "Honestly, who cares?")
- slifin 8y agoModern PHP is class based, the on going ignorance of PHP continues to insulate their own bubble
- Dylan16807 8y agoIn what way does it lie?
- megous 8y agoThere are no classes, just functions. 'class {}' is a function. Try it.
- Dylan16807 8y agoWould your definition classify most of lisp as a lie? It being implemented with a function shouldn't matter. What about the actual behavior is wrong for a class?
- megous 8y agoIt's not implemented with a function. It literally is a function (object constructor). class a {} typeof a == 'function' Objects in JavaScript are not class based. You can read here about the diferences: http://www.ecma-international.org/ecma-262/6.0/#sec-objects http://www.ecma-international.org/ecma-262/6.0/#sec-objects
- Dylan16807 8y agoThere is no 'class' type. That doesn't make classes fake, any more than a linked list or B-tree is 'fake' in C. As that link says, objects are not fundamentally class-based because objects don't have to have a class. But you could add classless objects to almost any language without making their classes fake. And when it talks about inheritance, well, you can inherit state in C++ too, it's called 'static'. Or in shorter form: It's not class-based but it does have classes.
- kazinator 8y agoThere are no integers in Lambda calculus, only natural numbers Church numerals built out of functions. That doesn't make numeric support a "lie" in Lambda Calculus.
- mschuetz 8y agoJS classes look like classes, behave like classes, and for all practical purposes are classes. They were one of the most useful additions to JS in recent years and make code so much more readable compared to hacking things together with the prototype system. With the added bonus, that you can still modify the prototype of a class to replace functions for all already generated instances of that class.
- adrianhel 8y agoDon't disagree, but for React users onClick={this.doStuff.bind(this)} is pretty common for newbies who just read it somewhere and don't know of the perf implications of bind. But personally I prefer prototypal inheritance and the everything is an object mentality.
- deleted 8y ago[deleted]
- munificent 8y ago> I already have a hard enough time teaching programmers about prototypical inheritance without the language actively lying to them. One way to look at it is that you could consider not teaching the underlying prototypal inheritance model at all. If students will rarely run into code that relies on it, it may be vestigial semantics. Think of it like how people used to teach patterns in C for doing object-oriented programming. For example, you could have a struct whose first field was a pointer to a table of functions for the operations you could perform on the object. In other words, how to implement your own vtables from scratch. When C++ came along, it was still useful to understand vtables sometimes, but it wasn't something every programmer needed to fully internalize. C++ let them program at a higher level of abstraction. > And it feels like an odd move in that class based OOP isn't the zeitgeist it once was. Citation needed. :) Two of the newest, fastest growing languages are class-based: Kotlin and Swift. I'm not aware of any new prototype-based language that has noticeable growth. Prototypes are a neat idea, but I think the market has pretty clearly shown that classes are a better practical approach to OOP.
- agd621 8y agoI don’t disagree that prototype is rare in real world practice but, anecdotally, it has come up in ~20% of my interviews in some fashion. That’s enough that I would be upset if the person teaching me JavaScript didn’t also teach me prototypal inheritance.
- thekaleb 8y agoI only bring up the prototype to determine if I would classify the interviewee as a senior JavaScript developer or not.
- adrianhel 8y agoObject.defineProperty('senior', { value: true, enumerable: false })
- scarface74 8y agoThere are two things I would expect even a mid level developer to know - how prototypical inheritance works and how “this” works in JS.
- kowdermeister 8y ago> without the language actively lying to them What does class mean?