美はシンプルさに宿る – プログラマが知るべき97のこと

Beauty-Is-in-Simplicity

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

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

There is one quote that I think is particularly good for all software developers to know and keep close to their hearts:

ひとつプラトンの言葉を引用します。ソフトウェア開発に携わる人ならば是非知っておくべき言葉、常に心に留めておくべき言葉だと思います。

Beauty of style and harmony and grace and good rhythm depends on simplicity. — Plato

「文章にしろ、和音にしろ、リズムにしろ、美しく、優雅なもの、優れたものはすべて、シンプルである。」— プラトン

In one sentence I think this sums up the values that we as software developers should aspire to.

この言葉には、ソフトウェア開発において大事にすべきことが見事に要約されていると思います。

There are a number of things we strive for in our code:

プログラマがコードを書く時に留意すべきことはいくつかありますが、まとめればだいたい次のようになるでしょう。

  • adability
  • Maintainability
  • Speed of development
  • The elusive quality of beauty

  • 可読性
  • 保守性
  • 開発効率
  • (言葉で表現するのが難しい)美しさ

Plato is telling us that the enabling factor for all of these qualities is simplicity.

プラトンの言葉が教えてくれるのは、シンプルであることを心がければ、上のすべてが達成されるということです。

What is beautiful code?

4つ目の「美しさ」とは何でしょうか。

This is potentially a very subjective question.

コードが美しいとはどういう意味なのかは、暖昧で、なかなか明確にはわかりません。美しいかどうかは、どうしても主観的な判断になります。

Perception of beauty depends heavily on individual background, just as much of our perception of anything depends on our background.

何を美しいと感じるかは、その人の経験や噌好に大きく影響されるでしょう。美しさに限らず、感じ方というのは、どうしても一人一人違ってしまいます。

People educated in the arts have a different perception of (or at least approach to) beauty than people educated in the sciences.

たとえば、いわゆる「芸術家」の美的感覚(少なくとも「美しさ」に対する考え方)は、きっと科学者とは違っているでしょう。

Arts majors tend to approach beauty in software by comparing software to works of art, while science majors tend to talk about symmetry and the golden ratio, trying to reduce things to formulae.

芸術を学んだ人が「ソフトウェアの美しさ」という言葉を聞けば、それは芸術作品のような美しさのことだと思うでしょう。一方、科学を学んだ人は「ソフトウェアの美しさ」と聞くと、対称性や黄金比の話をしていると思うかもしれません。あるいは、できるだけコードの書き方を定型化すること、と解釈するかもしれません。

In my experience, simplicity is the foundation of most of the arguments from both sides.

私の経験から言うと、両者の間で最も違っているのが、「シンプルさ」というものに対する考え方のようです。

Think about source code that you have studied.

これまでに見たことがあるソースコードをどれでもいいので、頭に思い浮かべてみてください。

If you haven’t spent time studying other people’s code, stop reading this right now and find some open source code to study.

他人の書いたコードをあまり見たことがないという人は、本をいったん閉じ、オープンソースソフトウェアのソースコードを今すぐどこかから入手して、内容をよく見てください。

Seriously! I mean it!

冗談抜きで、今すぐです。

Go search the web for some code in your language of choice, written by some well-known, acknowledged expert.

検索すればすぐに見つかります。言語は問いません。できれば、著名なプログラマの書いたソースコードが良いでしょう。

You’re back? Good. Where were we? Ah yes… I have found that code that resonates with me and that I consider beautiful has a number of properties in common.

私はこれまでに、優れている、美しい、と思えるコードを多数見てきました。そこには、必ずいくつか共通の特徴があると気づきました。

Chief among these is simplicity.

その中でも特に重要なのが「シンプルである」ということです。

I find that no matter how complex the total application or system is, the individual parts have to be kept simple.

アプリケーションやシステムが全体としてどれほど複雑であっても、個々の部分を取り出してみると、すべてシンプルになっています。

Simple objects with a single responsibility containing similarly simple, focused methods with descriptive names.

単一の責務を持ったオブジェクトは、メソッドもすべて機能が絞り込まれており、名前を見ればすぐに、持っている機能がわかるようになっています。

Some people think the idea of having short methods of five to ten lines of code is extreme, and some languages make it very hard to do this, but I think that such brevity is a desirable goal nonetheless.

「メソッドのコードはどれも5行から10行くらいの長さにすべき」と言うと、あまりに極端な意見だと思う人もいるでしょう。言語によっては、その長さにすることが非常に難しいものもあります。しかし、それでも、それぐらいの短さを目指すべきだと私は思うのです。

The bottom line is that beautiful code is simple code.

美しいコードとは、突き詰めれば、シンプルなコードのことです。

Each individual part is kept simple with simple responsibilities and simple relationships with the other parts of the system.

システムを構成する各部分がすべてシンプルで、個々の部分が担う責務も最小限に抑えられていて、部分どうしの関連もシンプル、そんなコードです。

This is the way we can keep our systems maintainable over time, with clean, simple, testable code, keeping the speed of development high throughout the lifetime of the system.

シンプルできれいなコードになっていればテストもしやすく、開発速度を落とさずに長期間にわたる保守が可能になります。

Beauty is born of and found in simplicity.

美は、シンプルなものから生じ、シンプルなものに宿るのです。

By Jørn Ølmheim

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