数码鹭岛论坛

标题: 如何写出无法维护的代码[转] [打印本页]

作者: 翔子    时间: 2012-4-24 16:14
标题: 如何写出无法维护的代码[转]
原文: [url=http://coolshell.cn/articles/4758.html]http://coolshell.cn/articles/4758.html
英文原文: [url=http://mindprod.com/jgloss/unmain.html]http://mindprod.com/jgloss/unmain.html

酷壳里有很多我觉得很不错的文章,但是访问量最大的却是那篇《[url=http://coolshell.cn/articles/914.html]6个变态的Hello World》,和它能在本站右边栏“全站热门”中出现的还有“[url=http://coolshell.cn/articles/933.html]如何加密源代码”,以及[url=http://coolshell.cn/articles/1391.html]编程真难啊等这样的文章。可见本站的读者们的偏好,我也相信你们都是“身怀绝技”的程序员。所以,今天给大家推荐这篇文章,相信一定能触动大家的兴奋点。
这篇文章的原文在这里([url=http://mindprod.com/jgloss/unmain.html]http://mindprod.com/jgloss/unmain.html),我看完后我想说——
我把文章节选了一些,也并没有完全翻译,简译一下,也加入了一些自己的调侃。对于有下面这些编程习惯的朋友,请大家对号入座。另外,维护程序的朋友们,你们死定了!!
If builders built buildings the way programmers write programs, then the first woodpecker that came along would destroy civilization. (如果建筑师盖房子就像程序员写程序一样,那么,第一只到来的啄木鸟就能毁掉我们的文明)
~ Gerald Weinberg (born: 1933-10-27 age: 77) [url=http://www.geraldmweinberg.com/Site/Home.html]Weinberg’s Second Law
程序命名伪装欺诈
1
2
3
4
5
6
7
8
9
10
11
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 ];
}



1
2
#define local_var xy\
_z // local_var OK



1
2
3
#define xxx global_var // in file std.h&nbsp;
#define xy_z xxx // in file ..\other\substd.h&nbsp;
#define local_var xy_z // in file ..\codestd\inst.h



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef DONE
#ifdef TWICE
// put stuff here to declare 3rd time around
void g(char* str);
#define DONE
#else // TWICE
#ifdef ONCE
// put stuff here to declare 2nd time around<
void g(void* str);
#define TWICE
#else // ONCE
// put stuff here to declare 1st time around
void g(std::string str);
#define ONCE
#endif // ONCE
#endif // TWICE
#endif // DONE



文档和注释程序设计混乱你的代码测试其它这个文档中还有很多很多,实在是太TMD强大了,大家自己去看看吧。有精力有能力的朋友不妨把其翻译成中文。
总之,我们的口号是——
Write Everywhere, Read Nowhere(全文完)





欢迎光临 数码鹭岛论坛 (http://www.clore.net/forum/) Powered by Discuz! X3.2