Sampling algorithms for D

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Apr 18 08:54:01 PDT 2012


On 18/04/12 17:03, Somedude wrote:
> This looks very C++ ish.

Yea, it's a rewrite of code originally in C (not even ++ ... !).

> I can't comment very much, being myself quite noob, but I think you can
> do this, for style as well as performance:
>   - add pure nothrow everywhere you can.

I think there's very little if anything that could be marked pure -- too much of 
the code either calls random number generation, or calls functions that call 
random number generation.

Not sure about nothrow.  I kind of think that this stuff _should_ throw 
exceptions if something goes wrong.

>   - move some imports within the static if when possible, as close to
> their actual usage, and it's better to do:
> import core.time:clock_t, clock;

Useful to know.  I'm not going to do it in this case because that's only 
temporary code to demo the speed differences.  The imports are pretty much a 
copy-paste from std.random as this stuff is aimed for incorporation into 
std.random once it's been tested properly.

> You may also want to use a bit of contract programming for input and output.

Ahhh, good point, I'll look into that.

> Also not sure the _ convention for private attributes is recommended in D.

I'm copying what's already in place in std.random


More information about the Digitalmars-d-learn mailing list