Discuss here the best article iPad2 contest
Robert Jacques
sandford at jhu.edu
Tue Jun 7 08:42:15 PDT 2011
On Wed, 01 Jun 2011 20:47:16 -0400, Walter Bright
<newshound2 at digitalmars.com> wrote:
> [5] Have Your Efficiency, and Flexibility Too by Nick SAbalausky
> http://www.semitwist.com/articles/EfficientAndFlexible/SinglePage/
Overall, I thought it thorough, and enjoyable read, if a little too cute
for its own good in a couple of places. Just a couple of comments:
* Here's a shorter, cleaner alternative to isIGizmo from
ex5_meta_deadDuck1.d:
template isIGizmo(T)
{
immutable bool isIGizmo = is(T : Gizmo!(T.numPorts, T.isSpinnable));
}
* static asserts in their current incarnation (well, as of 2.052, I
haven't double checked 2.053) are broken and should be verboten. This is
because they halt compilation, instead of generating an _error statement,
whenever they are evaluated. So when evaluated in traits, template
constraints, etc. anything with a static assert doesn't compose. As an
alternative, putting a string by itself on a line produces just as good an
error message and composes with the rest of D. (It might also be a cross
language technique.) See
http://d.puremagic.com/issues/show_bug.cgi?id=5233 for an example.
* I think there's a minor error in ex5_meta_deadDuck2.d:
is`~interfaceName~`!(`~thisType~`), =>
is(`~interfaceName~`!(`~thisType~`)),
Also, inside a template you can use the template name to refer to itself.
So you could change "string thisType" to "T" and then use T.stringof and
mixin(declareInterface("IGizmo", Gizmo)); instead.
More information about the Digitalmars-d
mailing list