1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdio.h>
#include <stdlib.h>
void right(int p) { // GOOD
int a; // OK because it is definitely initialized in the if or the
// else, and there is no good default.,
if(p > 0) {
a = p * 10;
}
else {
a = p / 10;
}
}
void right_2(int p) { // GOOD
int a = p / 10; // Use this form if you have a natural "default" value
if(p > 0) {
a = p * 10;
}
// READABILITY and MAINTAINABILITY always take precedence over brevity.
}
void wrong_3() {
double d = 0;
d = 15;
}
void right_3() {
double d = 15;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2019 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.