A small style tip
David
d at dav1d.de
Sun Jan 1 15:05:06 PST 2012
Am 01.01.2012 23:16, schrieb Mail Mantis:
> 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?
Nice, I like it
More information about the Digitalmars-d
mailing list