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

Allow a class/mixin to implicitly apply a macro wherever it is mixed in or extended? #31

Open
jakemac53 opened this issue Aug 2, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@jakemac53
Copy link
Owner

jakemac53 commented Aug 2, 2021

I am not sure this is a good idea, but filing it to have a central area for discussion.

The general idea is to have a mechanism available whereby mixing in or extending a particular class would auto apply some macros to the class that mixed it in or extended it.

This would eliminate the need for annotations in some cases, and enable frameworks to "hide" the macro applications from their users. Consider for instance:

class MyWidgetState extends State<MyWidget> with AutoListener {}

Instead of:

@autoListen
class MyWidgetState extends State<MyWidget> {}

Potentially frameworks could even add macro applications to their base classes (ie: State or Widget) in this example.

Pros

  • Hides the magic in some cases
  • Potentially less boilerplate

Cons

  • Hides the magic, making it more magical, and less expected
  • Two ways to do the same thing. Some macro authors may choose to use this just to avoid the annotation, making there two ways to do exactly the same thing.
  • Potential overhead in more complicated class hierarchies that otherwise aren't necessary (if the mixin is only used to apply the macro for instance)
@jakemac53 jakemac53 added the enhancement New feature or request label Aug 2, 2021
@munificent
Copy link
Collaborator

Related: Allow a macro applied to a function to do something at every invocation site of the function. That could be nice for debug-only code so that the call can be completely eliminated, including the evaluation of its arguments.

@jakemac53
Copy link
Owner Author

Related: Allow a macro applied to a function to do something at every invocation site of the function. That could be nice for debug-only code so that the call can be completely eliminated, including the evaluation of its arguments.

I think that probably becomes #29 - or at least this could cover that use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants