legacy code retreat's triva game : the D version
Meta
jared771 at gmail.com
Sat Dec 21 11:40:17 PST 2013
On Saturday, 21 December 2013 at 15:03:34 UTC, bearophile wrote:
> Chris Cain:
>
>> https://dl.dropboxusercontent.com/u/2206555/uniformUpgrade.pdf
>
> From page 6:
>
> size_t[] counts = new size_t[](top);
> foreach(i; 0 .. 500_000_000)
> counts[uniform(0, top)] += 1;
>
>
> Modern D allows you to write better code:
>
> size_t[N] counts;
> foreach (immutable _; 0 .. 500_000_000)
> counts[uniform(0, $)]++;
>
> Bye,
> bearophile
I know immutable is a good thing, but don't you think `immutable
_` is a bit unnecessary in this case?
More information about the Digitalmars-d-announce
mailing list