コンパイラ・インタプリタを書く上での13の大罪

元ネタは,gccwikiより.
http://gcc.gnu.org/wiki/DeadlySins

P. J. Brownが1979年に書いた"Writing Interactive Compilers and Interpreters"(インタラクティブコンパイラインタプリタの製作)が出典らしいが,コンパイラインタプリタじゃなくても当てはまることが結構あって面白かった.

  1. 考える前にコードを書く
  2. コンパイラ制作者と全く同じ知識を,ユーザが持っていると仮定する
  3. 適切なドキュメントを書かない
  4. 言語規格を無視する
  5. to treat error diagnosis as an afterthought(あとからの思いつきでエラー診断を扱う?ちょっと意味が分からない)
  6. 絶対起きないことと,起こりそうにないことを同等に扱う
  7. コンパイラエンコーディングを,データフォーマットに依存させる(これも意味が分かりにくい.エンコーディングとは何を指すのかが不明瞭)
  8. 数値を,数値でないオブジェクトの為に使う
  9. 一度に全員の要求に応えたふりをする
  10. インタプリタの一時停止を考慮しない(Pythonなど,インタプリタが動的に実行を行う環境での話.C や C++ などの話ではない)
  11. コンパイラユーザビリティよりも,数学的美しさに重きを置く
  12. いかなるエラーも検知されないようにする(これもちょっと意味が分からない)
  13. ユーザにコンパイラのエラーを見つけさせる

若干意味が分からない項目があったが,耳が痛いものも含まれているなぁ・・・

  1. to code before you think.
  2. to assume the user has all the knowledge the compiler writer has.
  3. to not write proper documentation.
  4. to ignore language standards.
  5. to treat error diagnosis as an afterthought.
  6. to equate the unlikely with the impossible.
  7. to make the encoding of the compiler dependent on its data formats.
  8. to use numbers for objects that are not numbers.
  9. to pretend you are catering to everyone at the same time.
  10. to have no strategy for processing break-ins. (A break-in is when you interrupt an interactive compiler, and then possibly continue it later. This is meaningful in an environment in which the compiler is run dynamically, such as many LISP and some BASIC environments. It is not meaningful for typical uses of C/C++ (although there was at least one interactive C environment according to Chris Lattner).)
  11. to rate the beauty of mathematics above the usability of your compiler.
  12. to let any error go undetected.
  13. to leave users to find the errors in your compiler.