A small style tip

Mail Mantis mail.mantis.88 at gmail.com
Sun Jan 1 14:16:18 PST 2012


Just a small tip for those people, who use following code style:

if( cond ) {
  body
} else {
  body
}

I've found it very convenient to "attach" unittest block to my function
declatarions in a same way:

private int find_pos_divisor( int first, int second ) {
    int temp;
    while( second ) {
        temp = second;
        second = first % second;
        first = temp;
    }
    return abs( first );
} unittest {
    assert( find_pos_divisor ( 10, 20 ) == 10 );
    assert( find_pos_divisor ( 10, 0 ) == 10 );
    assert( find_pos_divisor ( 9, 6 ) == 3 );
    assert( find_pos_divisor ( 10, 3 ) == 1 );
}

Looks as a natural extension to the declaration, and helps to keep all
related code in one place. Did anyone found out any more convenient
D-specific conventions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120102/c210d975/attachment.html>


More information about the Digitalmars-d mailing list