‘Cleaning up code’ is a terrible thing. Redesigning WORKING code into different WORKING code (also known as refactoring) is terrible. The reason is that once you touch WORKING code, it becomes NON-WORKING code, and the changes you make (once you get it working again) will never be known. It’s like Programmer masturbation, it might make you feel good, but no one will probably know you did it.

– Paul Tyma


不過如果作者所謂的 ‘Cleaning up code’ 是指 ‘Refactoring’ 的話,我並不認同這樣的看法。在軟體界向來有『If it ain’t broke, don’t fix it.』的說法,盲目地遵從這樣的規則反而會導致破壞軟體架構的完整性與可維護性,程序員不該把它當成偷懶的藉口。

就我的經驗,一般存在於程式碼最大的問題就是『重複』,重複的程式碼不但佔用更多的記憶體,更是許多 bug 的潛在原因。 The Pragmatic Programmer 告訴我們『Don’t Repeat Yourself』及『Make It Easy to Reuse』,短短簡單的兩句話卻是良好設計風格的基礎。