6 ms·
It's prototypical OO. Don't swim against the current. Swim with the current. It's not inheritance - it is delegation. It's just like in several other object-o
by lispm 14y ago
It's prototypical OO. Don't swim against the current. Swim with the current.
It's not inheritance - it is delegation.
It's just like in several other object-oriented languages: Self, NewtonScript ( http://waltersmith.us/newton/OOPSLA95.pdf http://waltersmith.us/newton/OOPSLA95.pdf ), Object Lisp ( http://lispm.dyndns.org/docs/ObjectLisp-Manual.pdf http://lispm.dyndns.org/docs/ObjectLisp-Manual.pdf ), MacFrames, ...
This is a classic example that it is difficult to unlearn a concept.
Q: how long does it take to learn prototype-based OO?
A: a day is sufficient. If you know class-based OO you'll need three days.
- smosher 14y agoI have to plug Io: http://iolanguage.org/ http://iolanguage.org/
- epidemian 14y agoAnd don't forget its cuter descendant, Ioke: http://ioke.org/ http://ioke.org/
- smosher 14y agoOf course. I wish I could use Ioke, but JVM/CLR just aren't in the cards for me for the foreseeable. On the subject of derivatives, I think Oia is at a sweet-spot, being JS-hosted at ~1-2kSLoC (1/5th-1/10th that of Io): https://github.com/stevedekorte/oia https://github.com/stevedekorte/oia
- thezilch 14y agoI think that's the argument -- naming is hard. Most JS libraries want to expose a class-based model -- call it class(es) -- and often to appeal to the non-prototypical crowd. Tutorials and documentation are rife with Java'esque examples. Instead, said JS libraries should possibly be exposing said `new Class()` as `new Delegate()`.
- protomyth 14y ago"often to appeal to the non-prototypical crowd" Isn't that the sad part? Its like Java / C++ is it for a lot of people and every other language has to fit that pattern.
- coldtea 14y agoOr it might be that the prototype thing never really caught on and people want something more class like. Why assume prototypes are better or that people should adapt to whatever (potentially BS) way a language offers for organizing code, instead of the other way around (languages should adapt to the way people want to use them).
- protomyth 14y agoI don't think it was given a chance, and the language is prototype-based. It's like programming Smalltalk like it FORTRAN.
- PommeDeTerre 14y agoIn what way wasn't it given a chance? The JavaScript community has had well over 15 years to show that prototype-based OO is feasible. Yet we've seen nothing compelling produced in that time. Whenever it comes to getting real work done, we see JavaScript developers resorting to some imitation of the proper class-based OO functionality made available by so many other languages. At what point will people admit that JavaScript's attempt at prototype-based OO is a miserable failure? At least we're seeing some indication of this finally happening with the latest standardization efforts. It's unfortunate that this is coming so late, however, after so much JavaScript-based software has been written using a hodge-podge of the different ways to fake class-based OO.
- protomyth 14y agoI think we've seen 15 years of people trying to program Javascript like Java. I think we see the same programmers who bitch and moan every time we have a concatenative, Smalltalk(1), or DSL thread about how it is too different. I think we have seen that if it looks like C++ or Java, it needs to act the same way. I guess the old rule about FORTRAN is now true of Java. 1) to quote "how will I ever use and image-based language with source code control?"
- coldtea 14y ago>It's prototypical OO. Don't swim against the current. Swim with the current. The current seems to be what the developers want to do. And JS doesn't really let them. Why define the current as the arbitrary capability of a random language?
- PommeDeTerre 14y agoPrototype-based OO is one of those concepts that sounds good, but it's just not what's actually needed in practice. Class-based OO just happens to be more effective and useful when dealing with real-world problems. I don't think it's a problem with developers not understanding prototype-based OO; they do. It's just that they run into situations time and time again where class-based OO is a better option. Yet since JavaScript doesn't (yet) offer proper class-based OO functionality, developers needing or desiring such functionality are forced to implement it themselves. As anyone who has worked on any sizable, multi-developer JavaScript code base will surely know, there are many different approaches to simulating proper class-based OO in JavaScript. The maintenance headaches this causes are very real. The direction of the JavaScript current is just flat out wrong. It's not that developers should stop swimming against it; they're going in the right direction. The current itself should be reversed so that it aides the developers in the direction they want to go, rather than continually ramming against them.
- tantalor 14y ago> The maintenance headaches this causes are very real. Problems tend to occur when developers don't agree on code conventions. This has nothing to do with JavaScript or OOP.
- seanmcdirmid 14y agoHow quickly we forget the Treaty of Orlando. http://dl.acm.org/citation.cfm?id=62144 http://dl.acm.org/citation.cfm?id=62144 http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.55.482&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.55....
- pekk 14y agoconsidering that I apparently have to pay in order to read it (first link)...
- seanmcdirmid 14y ago
- aufreak3 14y agoThe OP argues well that it is not inheritance, but neither does the term "delegation" fit. For example, when I delegate a task to someone at work, that person is not expected to wear my shirt to work. The delegate is expected to complete the task using resources available to the delegate. Delegates are better viewed therefore as processes. If JS's facilities are viewed as inheritance or delegation, the language ends up being used in limited ways to express solutions. There is nothing sacrosanct about classes. I agree with the original authors of Self that one tends to freeze categories early on in a class based language, whereas in a prototypal system, the categories are fluid, with structure that can evolve over time as knowledge about the problem domain improves.
- lispm 14y agoI would not expect real-world behavior for programming language constructs. Terms like 'inheritance' and 'delegation' are so vague, that it gives only a very rough indication what it does in some programming language. If I want to understand a programming language feature, I read the language spec, a manual, or, if all fails, the source code of the implementation.
- aufreak3 14y ago> I would not expect real-world behavior for programming language constructs. While that's indeed an invalid expectation, the term "delegate" is used technically in Objective-C, for example, in a way that cannot be related to "prototypal inheritance". The "delegates" don't use the resources of the delegating object. Quite often, they provide resources or data to the delegating object. JS's prototype system doesn't fit this model of "delegate" either 'cos the "delegate" does appear as though it is wearing the delegating object's shirt. The delegate itself (if you still want to call it one) has no identity apart from the delegating object in JS, whereas that isn't the case in ObjC. > If I want to understand a programming language feature This is not so much about understanding a language feature. It is about a model of system design being force fitted onto the language constructs. The language feature itself is dead simple and doesn't need to be viewed through the filter of OO to "understand" it.