怎样写出别人无法维护的代码

640?wx_fmt=gif

导读:对,你没看错,本文就是教你怎么写出让同事无法维护的代码,保证不会被打死。

 
 


译者:陈皓 (@左耳朵耗子)

译文来源:酷壳 – CoolShell

http://coolshell.cn/articles/4758.html

原文:http://mindprod.com/jgloss/unmain.html


如果建筑师盖房子就像程序员写程序一样,那么,第一只到来的啄木鸟就能毁掉我们的文明。

——Gerald Weinberg


640?wx_fmt=jpeg



01 程序命名



640?wx_fmt=jpeg



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&nbsp;#define xy_z xxx // in file ..\other\substd.h&nbsp;#define local_var xy_z // in file ..\codestd\inst.h
#define xy_z xxx // in file ..\other\substd.h&nbsp;
#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 文档和注释



640?wx_fmt=png



04 程序设计



640?wx_fmt=jpeg



05 混乱你的代码



640?wx_fmt=jpeg



06 测试




07 其它



总之,我们的口号是——Write Everywhere, Read Nowhere


640?


有话要说?


Q: 你还见过哪些让你抓狂的代码?

欢迎留言与大家分享


猜你想看? 



更多精彩? 


在公众号对话框输入以下关键词

查看更多优质内容!


PPT | 报告 | 读书 | 书单 | 干货 

大数据 | 揭秘 | Python | 可视化

AI | 人工智能 | 5G | 区块链

机器学习 | 深度学习 | 神经网络

1024 | 段子 数学 | 高考


据统计,99%的大咖都完成了这个神操作

? 


640?wx_fmt=png


觉得不错,请把这篇文章分享给你的朋友

转载 / 投稿请联系:baiyu@hzbook.com

更多精彩,请在后台点击“历史文章”查看

640?wx_fmt=jpeg

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值