怎样写出别人无法维护的代码
導讀:對,你沒看錯,本文就是教你怎么寫出讓同事無法維護的代碼,保證不會被打死。
譯者:陳皓 (@左耳朵耗子)
譯文來源:酷殼 – CoolShell
http://coolshell.cn/articles/4758.html
原文:http://mindprod.com/jgloss/unmain.html
如果建筑師蓋房子就像程序員寫程序一樣,那么,第一只到來的啄木鳥就能毀掉我們的文明。
——Gerald Weinberg
01 程序命名
02 偽裝欺詐
{
????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?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。
//?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:?你還見過哪些讓你抓狂的代碼?
歡迎留言與大家分享
猜你想看??
2019上半年這10本新書,技術大牛們都在追著看
終于有人把中臺說清楚了
高能干貨:OpenCV看這篇就夠了,9段代碼詳解圖像變換基本操作
18段代碼帶你玩轉18個機器學習必備交互工具
更多精彩??
在公眾號對話框輸入以下關鍵詞
查看更多優質內容!
PPT?|?報告?|?讀書?|?書單?|?干貨?
大數據?|?揭秘?|?Python?|?可視化
AI?|?人工智能?|?5G?|?區塊鏈
機器學習?|?深度學習?|?神經網絡
1024?|?段子?|?數學?|?高考
據統計,99%的大咖都完成了這個神操作
??
覺得不錯,請把這篇文章分享給你的朋友
轉載 / 投稿請聯系:baiyu@hzbook.com
更多精彩,請在后臺點擊“歷史文章”查看
總結
以上是生活随笔為你收集整理的怎样写出别人无法维护的代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 图灵奖得主Bengio:深度学习让AI得
- 下一篇: 企业数字化转型与中台建设全攻略:什么阶段