New concept Mixin Methods

Paul Backus snarwin at gmail.com
Sun Dec 25 15:26:30 UTC 2022


On Sunday, 25 December 2022 at 11:07:30 UTC, Andre Pany wrote:
> The concept Mixin Methods can be used like this
>
> ```d
> class Animal {
>
>     mixin void fancyMethod(){
>         writeln(__traits(identifier, typeof(this)));
>     }
>
> }
> ```
>
> Due to the mixin statement, the compiler will copy the 
> fancyMethod into all sub classes of class Animal as method 
> overload.
>
[...]
>
> Does it make sense to create here a DIP or do you see any road 
> blocker?

I don't think this feature provides enough utility to justify a 
DIP.

Ideally, we should only add new features to the core language 
when we cannot solve our problem any other way, and each feature 
we add should be as powerful and general as possible, so that we 
can solve a large number of problems with a small number of 
features.

This proposal fails on both counts: the problem it solves can 
already be solved by using a mixin template in the subclasses, so 
all it really does is save a bit of typing; and it only saves 
that little bit of typing in this one, very specific scenario.


More information about the Digitalmars-d mailing list