Each one is from this style guide I'm reading.
1.
57. do-while loops can be avoided.
do-while loops are less readable than ordinary while loops and for loops since the conditional is at the bottom of the loop. The reader must scan the entire loop in order to understand the scope of the loop.
In addition, do-while loops are not needed. Any do-while loop can easily be rewritten into a while loop or a for loop. Reducing the number of constructs used enhance readbility.
So a practical example:
Code:
do {
printf( "Write a number between 1 and 10: " );
scanf( "%d%*c", &number );
} while( ( number < 1 ) || ( number > 10 ) );
I should instead write:
Code:
printf( "Write a number between 1 and 10: " );
scanf( "%d%*c", &number );
while( ( number < 1 ) || ( number > 10 ) ) {
printf( "Write a number between 1 and 10: " );
scanf( "%d%*c", &number );
}
It isn't too much redundant ( code repeated )?, how would you do it?
2.
51. C++ pointers and references should have their reference symbol next to the type rather than to the name.
float* x; // NOT: float *x;
int& y; // NOT: int &y;
The pointer-ness or reference-ness of a variable is a property of the type rather than the name. C-programmers often use the alternative approach, while in C++ it has become more common to follow this recommendation.
So I should write also things like FILE* fp instead of FILE *fp?