The Art of Maintenance Programming

The Art of Maintenance Programming

 

最近項目人員變動,有一半時間都在維護別人的代碼,真是有些不適應,主要是一開始對於Maintenance Programming沒啥認識,太想當然了,本以爲既能學東西還能算工作量。不知道其他人都是怎麼維護別人留下來的代碼的。

 

前兩天看到CodeProject上一篇短好文實說Maintenance Programming Good Practices的:

http://www.codeproject.com/gen/design/artmaintenance.asp

 

可惜看到有點晚了):

人家說了9條,也懶得翻了,沒看過的聽俺大概說說:


1. Get to Like It (先喜歡上它)

    說起來容易做起來可難,讓寫程序的心甘情願去維護別人的代碼,而且還要like,確實難。


2. Get Familiar with the Functionality of the Software You Maintain (熟悉你需要維護的軟件的功能)

    你得維護還得改bug,想不熟悉都難。但還是覺得一開始比較痛苦。


3. Get Familiar with the Architecture of the Software You Maintain(熟悉你所維護軟件的架構)

    熟悉熟悉多學一點東西。


4. Communicate with the Users(多跟用戶溝通)

    溝通一下也沒啥壞處。


5. If Possible, Communicate with Original Developers(如果可能,跟原來的那個開發人員多溝通)

    通常這個是不大可能的。要是人家還在,PM一般也不會讓別人來維護這部分代碼。


6. Keep the History of Changes (保留改動的記錄)

    這個基本上就靠版本控制軟件了。

 

7. Be Conservative (越保守越好)

    一開始還不信,有些維護起來比較痛苦的地方,我還試圖把它重寫一下,後來發現行不通的時候自己都傻了,只能退回到一個禮拜以前的狀態。

  • How would it benefit your organization and its customers? The fact that some code is ugly, or looks ugly to you is not per se a reason to rewrite it. If a customer wants a feature that can’t be added to existing code, that could be a reason to consider rewriting it.
  • Are you sure you understand what this code does and how it works?
  • Are you sure you understand how it interacts with other parts of the system, and which modules and functionality depend on the code you want to rewrite?
  • Are you sure you can make it better? Maybe you run into the same problems the original developers did, and make it same or even worse.

8. Test after Every Change You Make(每次有改動都跑一下測試代碼)

    這條對於C++寫的程序來說太難做到了,試過CppUnitTUTCppUnit還好一點,可以嵌到VC6IDE裏,但寫測試代碼也是不勝其煩。俺也知道Test driven是好東東,有誰用的得心應手一定要把好經驗分享一下。

 

9. Adopt Existing Code Conventions Even If You Don’t Like Them(即使你不喜歡原來的編碼規範也要接受它)

 

    Code conventions are something people get religious about。但是如果不強迫自己慢慢適應你的前任的編碼習慣(至少在你維護代碼的時候),到後面會越來越痛苦。作者說了,adopt one of the existing conventions, and don’t introduce yet another one.

 

 

發佈了27 篇原創文章 · 獲贊 1 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章