On Fri, Jan 1, 2010 at 09:12, bearophile <[email protected]> wrote:


> What are the parts of the D1/D2 languages that are both common enough in
> programs and not easy to remember, so you need to look them often in the
> docs (or in an example list, code snippets list, already written code, etc)?
> This list is partially subjective, but probably there are also some common
> trends.
>

- variadic functions. I can't for the life of me remember if it's
foo(...)
foo(a...)
foo(a, ...)
and I always forget there is also foo(int[] a ...). Quick, what's the
difference with foo(int[] a) ?
And when I look at them in the docs, I'm, like "OMG, *void!".
So I end up writing foo(T...)(T args) and all is for the best: I got the
types, I got the length, I can static-if-act on them, I can put guards and I
can even recurse on them!

void foo(T...)(T args)
{
    writeln(args);
    static if (T.length)
        foo(args[1..$]);
}

- mixin. I have template Foo(T, U). In my code, should I write:
Foo!(int, double);
mixin Foo!(int, double);
mixin( Foo!(int, double));

When I discovered D some time ago, that was something that stalled me :(


Philippe

Reply via email to