simple display (from: GUI library for D)

bearophile bearophileHUGS at lycos.com
Fri Apr 8 18:07:18 PDT 2011


Adam D. Ruppe:

> The struct is at least equal in simplicity:
> 
> image[x, y] = Color(r, g, b);
> 
> vs
> 
> image[x, y] = tuple(r, g, b);

A tuple is simpler, there is no new name to remember and use, new type to define, and 3-tuples come out of other generic computations, like zip:

foreach (col; zip(reds, greens, blues))
    image[x, y] = col;

Generally D programmers probably need to learn to use tuples a bit more seriously and often :-)


> Yes, my window object does this too. See the example here:
> http://arsdnet.net/dcode/simpledisplay_test2.d
> 
> win.eventLoop() does it.

I see. But those lambdas are a bit too much large put there. I suggest true named function moved elsewhere.

Some other notes to your code:
- generic imports like stdio are probably better before the most specific ones (this is done in well written Python code);
- Inside the (dchar c) {} a switch seems better.
- In Wrapped struct why are you using a checkLimits() instead of an invariant()?


> > http://rosettacode.org/wiki/Animate_a_pendulum
> 
> Heh, I think D will be winning that by Monday!

Good, but Rosettacode site isn't a competition :-)

Bye,
bearophile


More information about the Digitalmars-d mailing list