Allen Wirfs-Brock wrote:
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?

I do not think they add too much complexity, but after looking at the examples I think they are not needed - the }.prototype.{ and }.constructor.{ are sort-of nice starters of "instance" and "class" part of method definitions - they can even be seen as magic "section starters" until understood that they are in fact normal language constructs.

It is even less needed if 'extends' would be added to functions to create double chain and <| left to create single chain - I sort of asked myself in the AbstractClass <| function .... }.prototype.{ ... where the prototype gets its parent from. I already read <| as single-chain only operator.

Allen

Herby
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to