Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about decorators? #33

Open
allenwb opened this issue Mar 13, 2018 · 1 comment
Open

What about decorators? #33

allenwb opened this issue Mar 13, 2018 · 1 comment

Comments

@allenwb
Copy link
Collaborator

allenwb commented Mar 13, 2018

This proposal does not take any stand with respect to the Decorators Proposal and is largely orthogonal to it.

The basic mechanisms of decorators are still applicable to class definitions as extended by this proposal. However, the details of the decorator API would have to evolve to account for the different set of class element declarations introduced by this proposal.

One concern for users of decorations may be that there doesn't appear to be any way to decorate a list of identifiers to provide generative behavior. One way to address this would be, as part of generator support, to provide an additional kind of class body element that is simply a decorated list of IdentifierName but that no standard semantics other than decorator application. For example:

function nop() {};  //a decorator function that does nothing

class C {
  @nop x, y, z; //this does nothing
  @xyzzy a;     //throws if xyzzy is undefined
  @own  p, q;  //might be used to declare public own instance properties
  @publicRead
   var n;  //generate a read accessor method for instance variable n
}
@zenparsing zenparsing changed the title What about Decorators? What about decorators? Mar 14, 2018
@wycats
Copy link

wycats commented Mar 16, 2018

I'm not so sure that decorators are as orthogonal as this issue implies.

Having worked on decorators for quite some time now, it's clear to me that the current class suite co-evolved with decorators: many aspects of the design were fine-tuned with specific use-cases designed to be expressed via decorators.

On the one hand, when we attempted to integrate decorators into previous features, we always found aspects of those features that needed to be changed in order to accommodate decorator use-cases. On the other hand, we often found that we could strip down some desired "bells and whistles" from earlier proposals (e.g. protected) through better extensibility, but only but carefully thinking through the semantics of decorating the more minimal set of constructs.

In the past, I found it very useful that @littledan took the time to illustrate, even relatively early in the process, how theoretical (but fleshed out) decorators could be used to close the gap on those use-cases. Some of the examples from those exercises made it into the current draft of the decorator proposal, and I think it would be very helpful to get a sketch of what those examples would look like with a hypothetical decorator extension to this proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants