On Mon, 06 May 2013 17:13:00 -0400, Idan Arye <generic...@gmail.com> wrote:

On Monday, 6 May 2013 at 19:47:33 UTC, Diggory wrote:
It's a nice idea but personally I don't like the syntax much, for example it's completely non-obvious what "true" does when passed to the singleton mixin, or that the parameters to the property mixin are "type, name, condition, initial value".

I suppose you could do something like this:
mixin property!`int x = 1`;

The other problem is that I don't think it's beneficial to invite the use of mixins for such simple substitutions. I'd rather see the majority of code be standard D syntax, and the use of mixins be the exception rather than the rule. It's similar to how excessive use of macros in C++ is generally considered bad practice.

If D supported Java's annotation metaprogramming I could have implemented a syntax like:

     @Property(`a < 50`) int a = 1;

since it doesn't, I have to use mixin templates...

D supports @Property syntax (though I would suggest a different identifier) via User-defined-attributes. However, you will still need the mixin, I don't think it can add code.

This brings up a good idiom though. Since mixin is the only thing that can inject code, but its usage is ugly, @uda's can be useful for specifying nice parameters to the mixin, and you could have one mixin per class instead of per property. I think Manu uses this to great effect (was in his first talk).

-Steve

Reply via email to