Mukai Systems

一貫性にこだわりすぎるのは、狭い心の現れである

そろそろParenのStyle Guideを書こう。ということで、いろいろな言語のそれを読み漁っている。中でも面白かったのがPythonとCommon Lispだ。

Python

PEP 8

PythonのStyle GuideはPEP 8で定義されている。そして、PEP 8にはとても印象的なタイトルが付けられているセクションがある。1

A Foolish Consistency is the Hobgoblin of Little Minds

-- Python Enhancement Proposals: PEP 8 - Style Guide for Python Code

このセクションを要約すると次のようである。

定められた構文を持つPythonですら、一貫性を崩しうる自由度が存在するのである。いわんや、構文があってないようなParenにおいておや。

PEP 20

先に引用したPEP 8のセクション内にPEP 20について言及がある。PEP 20はThe Way of Pythonというスレッドのやり取りで生まれた格言を起源としたものであるらしい。

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!

-- Python Enhancement Proposals: PEP 20 - The Zen of Python

ちなみに、このためにimport thisという粋なイースターエッグが用意されている。2

実はこれに感銘を受けてParenにも似たような機能を作ってあったりする。

(import :paren)

Common Lisp

おそらく、Parenが最も参考しなければならないのはGoogleのCommon LispのStyle Guideであろう。ここにも非常に有益な格言がある。

Background

Common Lisp is a powerful multiparadigm programming language.

With great power comes great responsibility.

-- Google Common Lisp Style Guide

よくできたStyle Guideの序文は、その言語の思想や真髄を的確に表しているような気がしてならない。


[1] 翻訳では表題のように訳されている。

[2] なぜか、コードはrot13で暗号化されている。