导读:对,你没看错,本文就是教你怎么写出让同事无法维护的代码,保证不会被打死。
译者:陈皓 (@左耳朵耗子)
译文来源:酷壳 – 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
1.魏少军:外国供应商曾问我,如果中国不买芯片了,他们怎么办?!
3.谷歌和 Facebook 是如何给工程师定职级和薪水的?
5.树莓派 4 发布!新 OS 基于 Debian 10 Buster
免责声明:本文系网络转载,版权归原作者所有。如涉及作品版权问题,请与我们联系,我们将根据您提供的版权证明材料确认版权并支付稿酬或者删除内容。