想不想写出别人无法维护的代码,还不会被打死?

本文以幽默的方式介绍了如何编写让同事难以理解与维护的代码,包括命名混淆、文档误导、设计混乱等技巧,旨在反向教育程序员重视代码质量和团队协作。

640?wx_fmt=jpeg


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



 


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

译文来源:酷壳 – 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?

1.魏少军:外国供应商曾问我,如果中国不买芯片了,他们怎么办?!

2.谁先扛不住?英特尔美光恢复供货华为

3.谷歌和 Facebook 是如何给工程师定职级和薪水的?

4.587所大学90个一流学科榜:电子专业哪家强?

5.树莓派 4 发布!新 OS 基于 Debian 10 Buster

6.基于STM32的多种printf用法,你都知道吗?

640?wx_fmt=gif

免责声明:本文系网络转载,版权归原作者所有。如涉及作品版权问题,请与我们联系,我们将根据您提供的版权证明材料确认版权并支付稿酬或者删除内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值