2011年1月8日土曜日

The Zen of Python

Pythonのインタラクティブシェルでthisをimportすると
The Zen of Pythonを読むことができる。


>>> import this


英語のリハビリとして辞書片手に翻訳してみる。

-翻訳-
醜いよりも美しいほうがいい
わかりにくいよりも分りやすいほうがいい
複雑よりもシンプルなほうがいい
入り組んでいるよりも複合のほうがいい
ネストしているよりもフラットなほうがいい
密度は低いほうがいい
読みやすさが重要
特別な場合でも規則を破るほど特別ではない
けれども実用性は純粋性をしのぐ
明確に沈黙させているので無い限り、決してエラーを黙って通してはいけない
曖昧さに直面したとき、推測するという誘惑に負けてはいけない
明らかな方法がひとつ、なるべくひとつだけあるべき
たとえオランダ人以外には明らかでなかったとしても
何もしないよりは今やる方がいい
けれども今すぐにやらないほうがいいこともたびたびある
説明が大変な実装であるならば、それは良くないアイディア
説明が簡単な実装であるならば、それがきっと良いアイディア
名前空間こそが良いアイディア、これらをどんどんやっていこう


-原文-
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

0 件のコメント:

コメントを投稿