2022/03/12 (新增連結)
2025/05/21 (新增連結)
簡單的說就是為了維持程式碼的乾淨,重寫程式。從正面表列的概念來看,要先了解甚麼樣是乾淨的程式碼(Clean Code),從負面表列的概念來看,也可以從了解甚麼樣是不乾淨的程式碼(Code Smell),然後,重整不乾淨的程式碼。很多人都問,寫程式都來不及了,哪來的時間重整程式? 重點是,這些不乾淨的程式碼常常是開發效率的障礙(或者是bug的來源),越不去清理,只是留給自己越多的問題。
程式碼重整(code refactoring)對於軟體開發而言是相當重要,但是,敏捷式軟體開發會特別強調code refactoring的重要性,因為,敏捷式軟體開發會常常在後續的sprint動到前面sprint的程式碼,如果程式不乾淨,就會造成後面的sprint必須花更多時間去開發新功能並更動原本的功能,會使得敏捷式開發很難進行。所以,敏捷軟體開發會鼓勵開發者勇敢地進行程式碼重整,甚至應該預留程式碼重整的時間。
2021/12/28
2022/11/27 (補充內容)
重構的原理
Code Smell
重構的模式
參考資料
重構既有系統,邁向整潔架構 (搞笑談軟工,Teddy Chen)
Refactoring: code smells and refactoring techniques (same as Refactoring.Guru)
What to Do When You’ve Inherited Dysfunctional Code
The Process of Micro-Rebuilds
Suggest a Parallel Build
Salvaging Code Through Refactoring
Isolate and ring-fence
Refactor to the rules
Elect a Code Janitor
Lessons from 6 software rewrite stories
My takeaway from these stories is this: Once you’ve learned enough that there’s a certain distance between the current version of your product and the best version of that product you can imagine, then the right approach is not to replace your software with a new version, but to build something new next to it — without throwing away what you have.
敏捷不是為了迅速交付而不重視程式的品質,相反的有品質的程式才是迅速交付的基礎
The way to achieve fast delivery is to remove obstacles from our path. One such obstacle is crufty code. It’s an obstacle that can be removed incrementally through disciplined work. It isn’t dependent on process or methods, like “waterfall” or “agile.” We choose how to do our work every time we touch a keyboard.
Doing the work right, including tying up the loose ends, is beneficial for customers, funders, management, future maintainers, and ourselves.
You are refactoring code all wrong
The question then is, why SHOULD you refactor? I believe pragmatic refactoring has two goals:
Decoupling code
Code cohesion
Refactor → Organisation : Changing the organisation — to build the technology right.
Software Quality (吳濟聰老師資訊系統專案管理課程教材)
Clean Code
Code Smell
Code Review (吳濟聰老師資訊系統專案管理課程教材)
Code Analysis (吳濟聰老師資訊系統專案管理課程教材)