change mixins
Jonathan M Davis
jmdavisProg at gmail.com
Sun Feb 14 21:12:28 PST 2010
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?
I do like the idea of differentiating between normal templates and templates
intended to be mixed in. However, I'm a bit concerned that removing the need
for the mixin keyword when actually mixing it in could result in a loss of
clarity - especially when it's legal to give the mixin a name. If I see
foo!(int) handle;
I'm going to thing that you just declared a variable of type foo!(int). I
wouldn't expect it to be a mixin. And how could you tell except if the
variable is used or not? And if it isn't, then it makes it look like maybe
it's an unused variable. Disallowing the name would help
foo!(int);
(I don't know why you'd want the name in the first place), but I think that
it's much clearer to have
mixin foo!(int);
That way I know exactly what you're doing. It costs some extra keystrokes,
but I think that the additional clarity is well worth it.
So, I think that making templates intended to be mixed in have to be marked
with the mixin keyword is a good idea, but I think that it's a bad idea to
not require the mixin keyword when actually mixing it in.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list