Tuesday, 20 February 2007

Naming

When naming a variable, use namespace-like mechanism to aviod name-collision and always prefer long names. For instance, colum_num is better than cnum and C is a very poor choice.

Longer names tend to slow down the typing speed thus reduce the chance of typoes. It's true that more complie errors may occur, but consider 'shorter' programs easily compiled: there are often stupit bugs that have to be caught manually! For example,

for (int i = 0; i < column_num; i++) {
for (int j = 0; j < row_num; j++) {
//...
}
}

may cause a compile error if one typed 'for (int i =0; i < cloumn_num; i++)' and the 'shorter' version

for (int i = 0; i < C; i++) {
for (int j = 0; j < R; j++) {
//...
}
}

may contains 'for (int j = 0; j < C; j++)' and it will cause error extreamily difficult to discover.

No comments: