原文: How to conquer legacy code
鏈結
“How to conquer legacy code”
如何征服老舊的程式碼 (英文):
以下為中文導讀: (原文七分鐘可以讀完)
常常聽到許多人很害怕來解老舊程式碼裡面的 bug 尤其越是剛入門的工程師.甚至有些人會使用到 “ 通靈 “ 或是 “ 猜測 “ 來表示閱讀老舊程式碼的痛苦.
這一篇就是一篇很好的教學來教導你如何面對老舊的程式碼.
首先是心態問題,面對這樣的程式碼千萬不要抱著 “這麼不好的架構,我一定可以寫得比他更好的心態來看問題“
It’s easy to look at work that came before you and decide it’s no good and that you can do better. This is the wrong attitude. It will lead you down a very dangerous path.
建議的方式如下:
虛懷若谷看待老舊的程式碼,絕不輕易重寫.
試著畫出循序圖來解釋整個程式碼流程
儘量做最小的變動 (minimum viable change) 來修復問題
每次的修改讓原來的程式碼能夠更好一點
慢慢地,當你更熟悉之後,就可以仔細思考整個架構與流程上的問題.
想要在老舊程式碼上面增加新功能,千萬要依照著原先的思考流程.
如果有新的架構與流程修改,試著透過 Adapter Pattern 來開始整合.
同場加映: “The Best Programming Advice I Ever Got” with Rob Pike
Google 同為 Golang 發明者的 Rob Pike 曾經在某次採訪就有提到,受過最好的 debugging 建議就是來自 Ken Thompthon (C 語言的共同發明者)
“Thinking—without looking at the code—is the best debugging tool of all, because it leads to better software.”
最好的除錯工具,不是直接去面對程式碼而是仔細思考整段流程.因為它能夠引導你做出更好的軟體…
心得:
還記得當初學校畢業之後,本來還信心滿滿的.結果第一份工作到了視窗軟體開發的公司 (Intervideo Inc.) 就發現所有的環境都不了解之外,還得去面對超過三五年以上的程式碼.
要面對如此龐大的架構的老舊程式碼,當初的部門經理就很推薦我使用循序圖的方式來慢慢瞭解整體架構.透過這些方式進行最小變動的修改來解 bug ,並且慢慢的來了解整個軟體的架構.
後來對於系統架構越來越有了解後,更了解思考對於解決問題的重要性.不論是整體架構的思考,或是對於流程的改造與優化都有事半功倍的效果.
最近常常在推特或是臉書上看到大家對於老舊的程式碼困擾,於是把這篇文章介紹出來,希望能幫到更多的人.
第一天的心得 我的演講: 利用 Golang 架設 Line 機器人,作為網站的推廣大使 Modern Web 2016: Using Golang to build a smart IM Bot from Evan Lin 演講心得 之前 COSCUP 講得太快,所以不自主地把投影片的數量又加大不少.不過就變得太長. 太多部分在著墨 Golang,這也是因為這個場子沒有講解 Go 的人.會想要推廣 Golang 花太少來著墨 BOT 與 LUIS ,不少同學都是會後才來詢問. Tuning NGINX for High Performance 投影片,所有相關鏈結 Apache will handle whole service before response it, it might have problem for 10k connection. Nginx focus how to handle more usere in one server. To improve whole performance from architecture, please consider CACHE in any layer starting from Appliation. Basic Nginx placement: Host Nginx as load balancer or reverse proxy. Client <-- HTTP/2 --> NGINX <-- HTTP/1.X, FastCGI, UWSGI, etc --> Servers OS Tuning for Nginx Refer this link. net.core.somaxconn net.core.netdev_max_backlog net.ipv4.ip_local_port_range sys.fs.file_max /etc/security/limits.conf, nofile setting One connection will open two files open, when you receive 2000 connections it mean at least you need open file limit over 4000. Overcoming ephemeral port exhaustion (短暫的 port 耗盡) include local...
前提: 之前想好好的宣傳 Golang ,於是乎一次投了兩個研討會.其實本來問題是不大的,只是剛好是同個禮拜(一個週日,一個週四).真是太棒了 (昏倒…) 不過今天相當的開心的跟了碼天狗的幾位作者 ( 同時也是講者 ) LY ,海總理還有特地趕來聚會的 Tim Kuo . 還有新認識的一堆講者. 難怪不少研討會都說,想要認識講者最好的方式就是… 成為講者. Douglas Crockford (Paypal) - Typing 投影片 History of Typing: Language Alphabet (upper) Alphabet (lower for writing) Typing The indent of key is to avoid key collision. The arrange also to avoid collision. “0” should come before “1”, all keyboard arrangement still wrong for now. ASCII code original use to for “writer” not “computer” Old typewriter history: One key combine with two word (upper/lower), Shift key to machanical shift the key to another one. Ctrl key is to call key control charactor if exist. (TAB is control part in “i” key. Return key to return to the begin of line (just like 0x0a) Line feed key to scroll papper line (just like 0x0d ) 心得: 從一開始語言的起源,到了字母的發明,最後到了打字 (Typing) . Douglas 說許多科技其實其來有自,你必須要好好了解科技的源頭,了解許多事情的原因,你才會了解為什麼會有這些相關科技的產生. 舉例而言,拿很古老的打字機上面的鍵盤排列來說: Shift key 一開始打字機為了要能顯示大小寫,其實一個按鍵黏著大寫與小寫的字母.而 Shift 就是要能夠機械式地移動( shift it ) 那個硬件去切換大小寫. Control key 現在已經越來越少使用了,其實一開始鍵盤上面是沒有 Tab...