What do we still need from a class-like abstraction (was: `this`: methods versus functions)
I wholeheartedly agree that mixin composition is superior to both
prototype and class-based inheritance. I'm not sure I entirely follow
your point regarding this', though. (TBH, I'd prefer not having a
this' keyword at all, because not being alpha-convertible, it doesn't
really compose with nested definitions, and invites subtle mistakes --
a lightweight syntax for binding an arbitrary identifier to self seems
better.)
The traits proposal currently is nice indeed, but also quite heavy on going through reflective meta levels. It will require significant work to make that efficient. But I believe there is potential for VMs optimizing e.g. nested closure creation for certain patterns. Though obviously, implementers currently have other priorities (like catching up with ES6 features first :) ).
The only value prototype inheritance gives is the fact you can change the prototype and changes are reflected.
If you do not want that feature then use mixins.
On Nov 10, 2011, at 7:59 AM, Mark S. Miller wrote:
My previous proposal for class-like sugar for traits composition was not popular. Whereas, in the absence of problem #5, I suspect the traitsjs library would be. As previously observed on this list, traitsjs is more JavaScripty. Ideal would be for JSVMs to magically make traitsjs efficient without requiring any language changes. If this is infeasible, perhaps we should instead be looking for the minimal language change that would enable a revision of traitsjs to run efficiently on ES-nest-next JSVMs.
The brendaneich.com/2011/01/harmony-of-my-dreams/#sharp_functions proposal, while out of date now, did try to support concise joined/frozen functions, joined up to the nearest relevant closure. If that is the constructor, you still have a sharp function per method per instance, but if the methods use only |this| and their parameters.
How HoBD sharp functions handle |this| was not totally clear. We talked at the January meeting about supporting only lexical |this|, only caller |this|, and (perhaps in March) "soft binding" where lexical |this| is the default but it can be overridden by caller |this|.
I say ES-next-next because it is too late to consider any such language change for ES-next. However, implementation experiments need not wait.
To revive the HoBD sharp-function idea at this point, I would want to get tenative agreement on |this|-binding. Your thoughts welcome.
On Nov 10, 2011, at 2:07 PM, Brendan Eich wrote:
On Nov 10, 2011, at 7:59 AM, Mark S. Miller wrote:
My previous proposal for class-like sugar for traits composition was not popular. Whereas, in the absence of problem #5, I suspect the traitsjs library would be. As previously observed on this list, traitsjs is more JavaScripty. Ideal would be for JSVMs to magically make traitsjs efficient without requiring any language changes. If this is infeasible, perhaps we should instead be looking for the minimal language change that would enable a revision of traitsjs to run efficiently on ES-nest-next JSVMs.
The brendaneich.com/2011/01/harmony-of-my-dreams/#sharp_functions proposal, while out of date now, did try to support concise joined/frozen functions, joined up to the nearest relevant closure. If that is the constructor, you still have a sharp function per method per instance, but if the methods use only |this| and their parameters.
Oops, lost the end of the last sentence: ", then you win".
Note that the traitsjs library provides:
TraitsJS also has the same problems that presently deter people from using objects-as-closures: 5) Without VM support, it costs at least an allocation per method per instance, making it much too expensive. (See micro benchmarks in < static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/pubs/archive/37485.pdf
I think I am satisfied at this point that "prototypes as classes" has made a plausible enough start on addressing point #6 in its own way, without introducing an explicitly class-like abstraction, that we may not need classes-as-sugar for prototypal inheritance. This leaves #5 as thepressing problem for use of either safe pattern: objects-as-closures (as below) or traits (as in traitsjs or possibly eventually class-like sugar for them as previously proposed).
My previous proposal for class-like sugar for traits composition was not popular. Whereas, in the absence of problem #5, I suspect the traitsjs library would be. As previously observed on this list, traitsjs is more JavaScripty. Ideal would be for JSVMs to magically make traitsjs efficient without requiring any language changes. If this is infeasible, perhaps we should instead be looking for the minimal language change that would enable a revision of traitsjs to run efficiently on ES-nest-next JSVMs.
I say ES-next-next because it is too late to consider any such language change for ES-next. However, implementation experiments need not wait.
On Thu, Nov 10, 2011 at 7:19 AM, Andreas Rossberg <rossberg at google.com>wrote: [...]