Do Maximally Minimal classes carry their weight?

Allen Wirfs-Brock allen at wirfs-brock.com
Mon Apr 2 23:15:15 PDT 2012


On Apr 2, 2012, at 5:00 PM, John J Barton wrote:

> Allen's original post on this thread offered two choices:
>   1) extended object literals, (good building blocks).
>   2) both, (because class gives 80% and thus they complement).
> Erik and Tab are arguing for 
>   3) Min-max classes (we need 80%, not building blocks).
> The current winner no one wants:
>   4) do nothing.
> 
> Allen's large examples illustrates one point for me:  the class syntax differences 
> are not very big, compared to the other changes.

but the class syntax maybe what is needed to standardize a baseline class model.

> 
> One important question for me: can the results of class syntax be used as 
> building blocks without the object-literal extensions? I mean: can the objects
> built from class syntax be used meta-programming even if they are (deliberately) 
> not prefect tools for that purpose? Can the solution for 80% help with the last
> 20% or at least no hinder?

I have a couple thoughts

The "superclass" expression provides useful  extension point:

class foo extends Mixin(bar, trait1,trait2,trait3} {
    constructor() {}
    method1() {}
}

In the above example you can think of Mixin as a higher order class that generates the actual "superclass".

It may also be useful to define class initialization as calling invoking a method on the "superclass" after the subclass has been constructed but before its value is bound.  EG:

      class foo extends expr {constructor() {} }

initializes as:
      const foo = expr. at initializeSubclass(<new constructor object with initialized prototype>);

This would give superclasses significant control over the initialization of subclasses allowing things such as injecting additional properties, setting property attributes, etc.

Finally, if you want to create more elaborate class abstractions I think you would want to parameterize them using object literals rather than class expressions:

let Thing = JJBClass({
   primarySuper: Entity,
   mixins: [a,b,c],
   constructor() {},
   instanceMethods: {
      method1() {}
      method2(){}
   },
   classMetods: {
      cmethod1() {}
      cmethod2(){}
   }
};

rather than:

let Thing = JJBClass({
   base: class extends Entity {
      constructor() {}
      method1() {}
      method2(){}
   },
   mixins: [a,b,c],
   classMetods: class { //these get copied to constructor
      cmethod1() {}
      cmethod2(){}
   }
};

 Alen   




More information about the es-discuss mailing list