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...
(Declaimer: I do not want to imply here that Java is a good
language. Java is a terrible language. Annotation metaprogramming
is it's only redeeming feature, and even that feature is far too
complex for common use...)
Anyways, I'll have to add a new trait template to extract the
name from the declaration(Compile time regex are too slow), but I
think I can pull off the style you suggest. However, we still
need an extra template argument for the verifier, something like
this:
mixin propertyVerified!(`int x = 1`, `a < 50`);
Is this readable enough?