Do Maximally Minimal classes carry their weight?

Allen Wirfs-Brock allen at wirfs-brock.com
Sat Mar 31 10:40:35 PDT 2012


At the recent TC39 meeting a couple people raised the concern  that maximally minimal class definitions [1] don't really do anything that isn't also possible with enhanced object literals [2] and hence the additional complexity they add to the language is undesirable. Only one of these alternatives should be in the language and enhanced object literals are preferable because they are  compositional primitives that can be used to create a variety of higher level abstractions. 

The counter argument is that max-min class definitions and enhanced obj lits support different use cases and that both are important.  The class definitions present a more complete abstraction that exposes the class model  already latent in the ES built-in objects.  Even though max-min classes don't have all possible class bells and whistles they are a good "80%" solution that  will likely to widely used and will facilitate code usage that crosses developer and library boundaries.  Enhanced object literals are independently useful as compositional primitive and can be also be used to augment the capabilities of max-min class definitions. 

To make this debate more concrete, I've created new versions of my Smalltalk-style collections class library [3] that use Max-min class definitions. These new versions also use arrow functions and I've added a version of the object literal based base-line that also uses arrow functions.  Comparing these versions are a good way see the differences (and similarities) between the max-min classes and obj lit approaches to defining object abstractions in ES6.

The new files are:
ST80collections-exp11.js [4]:  This is the base line that uses the <| and .{} pattern to defines "classes".
ST80collections-exp10.js [5]:  Shows basic use of max-min classes declarations.  It uses Object.defineMethod to define class methods.
ST80collections-exp9.js   [6]:  Shows max-min classes declarations with .{} used to define class methods and per instance properties.

Comparing either exp9 or exp10 to exp11 shows how max-min classes differ from just using extended object literals.
Comparing exp9 to exp10 shows how .{}  can pleasantly augment max-min class definitions in support of uses cases that they do not directly support.

What do you think?  Assuming that we will have some forms of enhanced object literals in ES6, are max-min classes also worth the additional complexity they add to the language? 

Allen

[1]: http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes 
[2]: http://wiki.ecmascript.org/doku.php?id=harmony:object_literals 
[3]: https://github.com/allenwb/ESnext-experiments 
[4]: https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp11.js 
[5]: https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp10.js 
[6]: https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp9.js 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120331/c8cd1060/attachment.html>


More information about the es-discuss mailing list