08童子军规
Last updated
Last updated
The Boy Scouts have a rule: "Always leave the campground cleaner than you found it." If you find a mess on the ground, you clean it up regardless of who might have made the mess. You intentionally improve the environment for the next group of campers. Actually the original form of that rule, written by Robert Stephenson Smyth Baden-Powell, the father of scouting, was "Try and leave this world a little better than you found it."
童子军有一条规则:“永远让营地比你刚到来时更干净。“如果你发现地上乱七八糟,不管是谁弄的,你都要清理干净。你会仔细的为下一批露营者改善环境。实际上,童子军之父罗伯特·斯蒂芬森·史密斯·巴登-鲍尔写的规则的最初形式是“试着让营地比你刚到来时要好一点”。"
What if we followed a similar rule in our code: "Always check a module in cleaner than when you checked it out." No matter who the original author was, what if we always made some effort, no matter how small, to improve the module. What would be the result?
如果我们在编码时遵循一个类似的规则:“保证你修改的模块总是比你检出它时更加整洁“,会怎么样?不管最初的作者是谁,不管多么小的改进,如果我们总是努力改进模块,会有什么结果?
I think if we all followed that simple rule, we'd see the end of the relentless deterioration of our software systems. Instead, our systems would gradually get better and better as they evolved. We'd also see teams caring for the system as a whole, rather than just individuals caring for their own small little part.
我认为,如果我们都遵循这个简单的规则,我们的软件系统将不再会不断恶化。相反,我们的系统会不断进化,而逐渐变得越来越好。我们也会看到 团队 会关心整个系统,而不仅仅是个人只关心自己那一小部分。
I don't think this rule is too much to ask. You don't have to make every module perfect before you check it in. You simply have to make it a little bit better than when you checked it out. Of course, this means that any code you add to a module must be clean. It also means that you clean up at least one other thing before you check the module back in. You might simply improve the name of one variable, or split one long function into two smaller functions. You might break a circular dependency, or add an interface to decouple policy from detail.
我不认为这个规则很难执行。您不必在签入之前使每个模块都变得完美。你只要让它比你签出的时候 好一点 就行了。当然,这意味着你 添加 到模块中的任何代码都必须是干净的。这也意味着在重新签入模块之前,你至少要清理一件其他事情。你可以简单地改变一个变量的名称,或者将一个长函数拆分成两个较小的函数。你可以打破循环依赖关系,或者添加一个接口来将策略与细节分离。
Frankly, this just sounds like common decency to me — like washing your hands after you use the restroom, or putting your trash in the bin instead of dropping it on the floor. Indeed the act of leaving a mess in the code should be as socially unacceptable as littering. It should be something that just isn't done.
坦白说,这听起来就像是一种通用的礼仪---比如在你上完厕所后洗手,或者把你的垃圾放在垃圾箱里,而不是扔在地板上。事实上,把代码弄乱的行为应该和乱抛垃圾一样为社会所摒弃。这属于那总 只是没用心做的事情 。
But it's more than that. Caring for our own code is one thing. Caring for the team's code is quite another. Teams help each other, and clean up after each other. They follow the Boy Scout rule because it's good for everyone, not just good for themselves.
但不止这些。关心我们自己的代码是一回事。关心团队的代码是另一回事。各团队互相帮助,互相清理代码。他们遵循童子军规则,因为这对每个人都有好处,而不仅仅是对自己有好处。
by