change mixins

sybrandy sybrandy at gmail.com
Sun Feb 14 20:04:10 PST 2010


On 02/14/2010 04:31 PM, Walter Bright wrote:
> Right now, mixins are defined and used as:
>
> template foo(T) { declarations... }
>
> mixin foo!(int) handle;
>
> The proposal is to switch it around:
>
> mixin template foo(T) { declarations... }
>
> foo!(int) handle;
>
> to follow the notion that mixin templates are very different from
> regular templates, and that should be reflected in their definition
> rather than use.
>
> What do you think?

Personally, I like it.  I wrote my first batch of code using mixins a 
couple weeks ago and I hate the fact you have to specify "mixin" every 
time you use the template.  To me, this seemed very annoying, especially 
when I was trying to implement something in a way where depending on a 
compiler switch, the functionality would or would not be there.  To me, 
the proposal makes it look more like a normal function, which means less 
typing and clutter in the code.

Btw: I was doing this for a logging library that I was working on.  As 
one can deduce, when you have a lot of logging statements in your code, 
being able to leverage a mixin to cleanly enable/disable the 
functionality in conjunction with a compiler switch can have an impact 
on performance.

Casey



More information about the Digitalmars-d mailing list