Thursday, April 23, 2009

PEP 8: Hard Coding Poor Style?

PEP 8, the style guide for Python, contains a great deal of sensible advice for writing readable code. The discussion of comments, explanatory prose sprinkled throughout a program, insisted upon some interesting conventions.

1. "You should use two spaces after a sentence-ending period."

The two space rule is no longer standard practice. In fact, the vast majority of contemporary style guides recommend one space.

2. "When writing English, Strunk and White apply."

The linguists at Language Log blame the Elements of Style for Fifty Years of Stupid Grammar Advice. The style advice is at times vacuous (e.g. "Omit needless words", "Be clear"), at other times simply incorrect (avoid adjectives and adverbs, 'none' takes the singular, never begin a sentence with 'However', etc.).

The recommendations on the readability of code in PEP 8 reflect that they were compiled by experts at that craft. The above recommendations drift into the readability of prose, and appear decidedly less authoritative. To be fair, I doubt these conventions are carefully followed. I was mostly struck by the hubris of providing a rule in a programming guide about an authoritative source for English grammar or style.