Entropy
/ éˆÉ›ntrÉ™pi /:缺乏秩序或可预测性; 逐渐陷入混乱。
物理学中的熵是指系统中“混乱”的程度。 热力学定律保证宇宙中的熵趋于最大。
尽管物理定律不适用于软件,但是熵却很难解决。 当软件混乱增加时,程序员称之为“软件腐烂。”
The Broken Window Theory
软件腐烂始于一扇破窗户。
一个破损的窗户,如果长时间不予修理,将给人一种被抛弃的感觉。 所以另一个窗口坏了。 人们开始乱扔垃圾。 出现涂鸦。 开始严重的结构损坏。 在相对较短的时间内,该建筑物遭到损坏,超出了业主对其进行修复的期望,而废弃感也变成了现实。
The Boy Scout Rule
有时我会一起乱砍代码,因为整个组件有些乱七八糟。 这只会使代码变得比现在更糟,并且以后很难更改它。 相反,如果您在一个团队/项目中工作,这些代码的编写简洁,设计合理且优雅……您可能会格外小心,不要弄乱它。 不要让“破损的窗户”得到修复。 发现每个问题后立即修复。保持代码清洁干净。
Dealing With Entropy
As Uncle Bob says, it’s not enough to write code well, the code has to be kept clean over time. If we all checked-in our code a little cleaner than when we checked it out, the code simply could not rot. The cleanup doesn’t have to be something big. Change one variable name for the better, break up one function that’s a little too large, eliminate one small bit of duplication, clean up one composite if statement.
Done And Gets Things Smart
程序员都很聪明,可以把事情做好,但是我们应该养成把事情做好并使代码变得聪明的习惯。
“You want someone who, when you give them a project to research, will come in on Monday and say: “I’m Done, and by the way I improved the existing infrastructure while I was at it.” – Stevey’s Blog Rants
TL;DR
You see evil and you destroy it. Always be refactoring. I’ve found that the following prioritization helps quite a lot:
bugs > refactoring > features
这适用于任何编程范例,而不仅限于OOP。 安迪·亨特(Andy Hunt)和戴夫·托马斯(Dave Thomas)在他们的书中对此进行了大量论述务实的程序员。 一定要检查一下并告诉我您的观点。
Øriginally posted here.