Description
I'm filing this issue as a place to discuss whether using the new mixin
syntax for non-supermixins is a good idea. I do not wish to pollute issue #32 with this discussion, as I'd like that issue to be focused on the semantics of extends
w.r.t. mixin
.
The arguments presented so far:
Personally I have no objection to being able to use "with" with a true class. I would not want a lint that discourages such use.
I don't see much value in the "mixin" keyword. I'm ok with having it if it makes the language easier to process in the context of supermixins. I would not encourage people to move to that keyword except where required by the supermixin restrictions.
In particular, I would not change WidgetsBindingObserver to use the "mixin" keyword.
mixin
comes certain restrictions on what you can do with the class, such as:
- mixins cannot extend other classes
- mixins cannot have constructors and factories
- mixins cannot be instantiated directly
These properties protect mixin authors from accidentally breaking their users. I believe this is an important property for keeping the Flutter/Dart ecosystem healthy. Mixin usage is much higher than mixin authorship and therefore the cost of using mixin
vs class
is dwarfed by the stability guaratees the mixin
semantics provide.
Some examples in Flutter that may be used as super-classes or as mixins:
Updates to the original issue description:
- Added examples from Flutter