digitalmars.D - A small style tip
- Mail Mantis (25/25) Jan 01 2012 Just a small tip for those people, who use following code style:
- David (2/27) Jan 01 2012 Nice, I like it
- bearophile (4/18) Jan 01 2012 It's an interesting idea, I will try it.
- F i L (17/45) Jan 01 2012 I've been playing with different style options, especially with
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?
Jan 01 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
Jan 01 2012
Mail Mantis:
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 );
}
It's an interesting idea, I will try it.
Bye,
bearophile
Jan 01 2012
On Sunday, 1 January 2012 at 22:18:05 UTC, Mail Mantis wrote:
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?
I've been playing with different style options, especially with
function contracts. Traditionally, I've used a new line per
bracket (at least for types and methods) but I've been playing
around with putting them after the definition. I've found
readability makes a huge difference that way if your variable
definition (auto, int, string, etc) are colored different than
keywords (if, static, public, etc).
class Person
{
string name;
void coolName(string name) in {
assert(name != "F i L");
} body {
this.name = name;
}
}
Jan 01 2012









David <d dav1d.de> 