ボーイスカウト・ルール – プログラマが知るべき97のこと

The-Boy-Scout-Rule

この記事は、「プログラマが知るべき97のこと」について、英語と日本語訳を記載したものです。

プログラマが知るべき97のこと(オライリー・ジャパン、2010年)
Kevlin Henney(編)、和田 卓人(監修)、夏目 大(訳)
各エッセイはCC-by-3.0-USによってライセンスされています。

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.

既存のコードを触る場合には、チェックイン前にどこか1箇所でいいので改善しましょう。

You might simply improve the name of one variable, or split one long function into two smaller functions.

変数名をより適切なものに変えたり、大きい関数を2つの小さくよりシンプルな関数に分割する、というのでもいいのです。

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 Uncle Bob

タイトルとURLをコピーしました