如何写出无法维护的代码
1、把注释和代码交织在一起。for(j=0; j<array_len; j+ =8){ total += array[j+0 ]; total += array[j+1 ]; total += array[j+2 ]; /* Main body of total += array[j+3]; * loop is unrolled total += array[j+4]; * for greater speed. total += array[j+5]; */ total += array[j+6 ]; total += array[j+7 ];}
2、隐藏宏定义。如:#define a=b a=0-b,当人们看到a=b时,谁也想不到那是一个宏。
3、换行。如下所示,下面的示例使用搜索xy_z变得困难。#define local_var xy\_z // local_var OK
4、代码和显示不一致。比如,你的界面显示叫postal code,但是代码里确叫 zipcode.隐藏全局变量。把使用全局变量以函数参数的方式传递给函数,这样可以让人觉得那个变量不是全局变量。
5、使用同意词。如:#define xxx global_var // in file std.h #define xy_z xxx // in file ..\other\substd.h #define local_var xy_z // in file ..\codestd\inst.h使用相似的变量名。如:单词相似,swimmer 和 swimner,字母相似:ilI1| 或 oO08。parselnt 和 parseInt, D0Calc 和 DOCalc。还有这一组:xy_Z, xy__z, _xy_z, _xyz, XY_Z, xY_z, Xy_z。重载函数。使用相同的函数名,但是其功能和具体实现完全没有关系。