先日購入した Perl Hacks - プロが教へるテクニック & ツール 101 選を讀んでゐて Perltidy と云ふソース・コードを整形するツールが在る事を知つたので入れてみた。
Gentoo なので、
# emerge -Dav dev-perl/perltidy
で終はり。
それで試しに使つて見た處、初期設定の儘だと整形規則が氣に入ら無かつたので、${HOME}/.perltidyrc を編輯して以下の樣にした。
# I/O Control #--standard-output # 整形結果は標準出力に出力する。 --standard-error-output # エラーは標準エラー出力に出力する。 --warning-output # 深刻でない警告も表示する。 # Basic Options --maximum-line-length=78 # 一行は最大 78 カラム。 --indent-columns=4 # インデントは 4 カラム。 --check-syntax # 文法を檢査する。 # Code Indentation Control --continuation-indentation=4 # 繼續行のインデントは 4 カラム。 # Whitespace Control --paren-tightness=2 # 丸括弧の内側は詰める。 --square-bracket-tightness=2 # 角括弧の内側は詰める。 --brace-tightness=2 # 中括弧(ブレース)の内側は詰める。 --block-brace-tightness=2 # ブロックの中括弧の内側は詰める。 --nospace-for-semicolon # for 文のセミコロンの前を詰める。 # Comment Controls --indent-block-comments # ブロック・コメントをインデントする。 # Line Break Control --cuddled-else # else, elsif では改行しない。
取敢へず暫く此で樣子を見る。
色々檢索してみると Perl ベストプラクティスでは以下の設定を推奬してゐるらしい。
-l=78 # Max line witdh is 78 cols -i=4 # Indent level is 4 cols -ci=4 # Continuation indent is 4 cols -st # Output to STDOUT -se # Errors to STDERR -vt=2 # Maximal vertical tightness -cti=0 # No extra indentation for closing brackets -pt=1 # Medium parenthesis tightness -bt=1 # Medium brace tightness -sbt=1 # Medium square bracket tightness -bbt=1 # Medium block brace tightness -nsfs # No space before semicolons -nolq # Don't outdent long quoted strings -wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=" # Break before all operators
括弧の内側に空白が入るのは好きでは無いのだが、此方に慣れる樣にした方が良いのかな。
Python には PythonTidy と云ふものが在る模樣。
Perl ベストプラクティスに準據するには、上に書いた樣に $HOME/.perltidyrc に一つ一つ書かなくても、
-pbp
亦は
--perl-best-practices
と書いて置けば濟むと「man 1 perltidy」*1には記して在つた。
と云ふ譯で、自分の $HOME/.perltidyrc も其乃樣にした。
體裁なんて凝り出したらキリが無いし。
*1 但し 20070508 版。