[Gecode] Some more tips for coding style...

Christian Schulte schulte at imit.kth.se
Mon May 10 15:33:08 CEST 2004


Dear all,

just some things that occurred to me when changing the subscribe/cancel
functionality:

Run Loops Backward by Default!

If you have a loop for (int i=0; i<n; i++) and the order of the iterations
do not matter, run it backwards:
	for (int i = n; i--; )
Why: it requires one register less (unless n is a constant of course). Quite
important on Intel as there are only so few registers. If you run backwards
use exactly the above pattern, so that everybody recognizes it.


Use Array Operations for Subscribing/Cancelling

The VarArray class has a subscribe/cancel function. Use it! Don't build your
own loop.


Use Boolean Variable Operations!

BoolVars feature handcrafted operations for testing and telling. Use them.
Use a b* for variable name that it is clear that it is a Boolean variable.


Have a Look Now and Then...

Please now and then check how things are done in the integer part. Try to
follow the style there.


Christian

--
Christian Schulte, http://www.imit.kth.se/~schulte/ 





More information about the gecode-users mailing list