4 ms·
I've started programming in JavaScript before or at the same time I started programming in Java and still find that the author's argument is mostly valid. It's
by romaniv 15y ago
I've started programming in JavaScript before or at the same time I started programming in Java and still find that the author's argument is mostly valid. It's not a matter of habit, it's a matter of consequences and the amount of knowledge you need to have to make basic language features work correctly.
Prototypes are simply more complicated than classes. They change behavior of objects, whereas classes _define_ behavior of objects. The syntax doesn't help it either.
- bryanlarsen 15y agoThat's your opinion. My opinion is that prototypes are simpler than classes. The distinction between a class and an object can be very tricky, especially once you get dynamic or introspective because then you run into the situation where classes are also objects.
- romaniv 15y agoIf it was simple, there would be no articles about "proper" ways to construct objects and arguments regarding whether using the "new" keyword is a a bad practice. It's absolutely ridiculous that such core language features need to be discussed and argued about so much.
- mistercow 15y agoThey don't need to be discussed and argued about. If the irrelevant flamewars are to be the standard by which a language is judged, then the only language that will ever pass muster is the one that is never released.
- batista 15y ago>That's your opinion. No, that's an objective statement, on which the creator of the language and some of the greater gurus of it, agree. >My opinion is that prototypes are simpler than classes. Not in the way prototypes are implemented in JS. The creator of the language was apologized lots of times for it's many warts (due to lack of design and time constraints plus limited initial scope for the language), and the greatest of its' gurus had to write a book called "Javascript, THE GOOD PARTS". Someone who cannot see the flows of Javascript's implementation of prototype inheritance, seriously cannot assess good and bad software design.
- mistercow 15y agoFirst of all, I'm not sure it's right to call Crockford "the greatest JavaScript guru". That's a stretch, to say the least. Secondly, you appear to be claiming that Crockford offers strong criticism of JS's inheritance model in The Good Parts. If that's what you took away from it, I think you would do well to reread that chapter. Of course JS's inheritance system is imperfect just like that of pretty much any other language.
- batista 15y ago>First of all, I'm not sure it's right to call Crockford "the greatest JavaScript guru". That's a stretch, to say the least. Well, he sure is on a very short list of js programmers. Who other can you add? Maybe Resig? Ashkenas? >Secondly, you appear to be claiming that Crockford offers strong criticism of JS's inheritance model in The Good Parts. If that's what you took away from it, I think you would do well to reread that chapter. No, I'm saying that Crockford doesn't like the way prototypal inheritance is implemented/exposed in javascript --not that prototypal inheritance is inherently bad. He even writes that the basic action of getting prototypal inheritance is not first-class in js: "In a prototypal system, objects inherit from objects. JavaScript, however, lacks an operator that performs that operation." And in order to use prototypal inheritance he has written a wrapper function to hide all the inheritance boilerplace correctly. (As has every other js programmer I know of, using several patterns).
- mistercow 15y ago> Prototypes are simply more complicated than classes. Only if you try to make them act like classes.
- blinks 15y ago> Prototypes are simply more complicated than classes. [citation needed] I'd argue the opposite: "Prototypes are simply more _intuitive_ than classes." OO-design says that X is-a Y is-a Z, with inheritance providing the main form of structure. Prototypical-design says that X is-like-a Y, but with these differences. This NPC (specific, X) is like any other NPC (general, perhaps the original NPC prototype), but with the name Fred and this custom AI code. They're different ways of thinking, but prototypes are certainly not more complicated than classes in the general case. ---- As for the syntax, though, I totally agree with you.
- mistercow 15y agoThis is a bit of a nitpick, but prototype based programming is still OO.