导读:对,你没看错,本文就是教你怎么写出让同事无法维护的代码,保证不会被打死。
译者:陈皓 (@左耳朵耗子)
译文来源:酷壳 – CoolShell
http://coolshell.cn/articles/4758.html
原文:http://mindprod.com/jgloss/unmain.html
如果建筑师盖房子就像程序员写程序一样,那么,第一只到来的啄木鸟就能毁掉我们的文明。
——Gerald Weinberg
01 程序命名
02 伪装欺诈
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 ];}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 ];
}
#define local_var xy\_z // local_var OK// local_var OK
#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
#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。
#ifndef DONE#ifdef TWICE// put stuff here to declare 3rd time aroundvoid 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 aroundvoid g(std::string str);#define ONCE#endif // ONCE#endif // TWICE#endif // DONE
// 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
03 文档和注释
04 程序设计
05 混乱你的代码
06 测试
07 其它
总之,我们的口号是——Write Everywhere, Read Nowhere
有话要说?
Q: 你还见过哪些让你抓狂的代码?
欢迎留言与大家分享
猜你想看?
更多精彩?
在公众号对话框输入以下关键词
查看更多优质内容!
PPT | 报告 | 读书 | 书单 | 干货
大数据 | 揭秘 | Python | 可视化
AI | 人工智能 | 5G | 区块链
机器学习 | 深度学习 | 神经网络
1024 | 段子 | 数学 | 高考
据统计,99%的大咖都完成了这个神操作
?
觉得不错,请把这篇文章分享给你的朋友
转载 / 投稿请联系:baiyu@hzbook.com
更多精彩,请在后台点击“历史文章”查看