[Anthy-dev 2388] コードの慣用表現

Back to archive index

YamaKen yamak****@bp*****
2005年 9月 16日 (金) 18:07:30 JST


ヤマケンです。

最近uimのコーディングスタイルについてちょっと議論がありましたが、
整形や細かい論理の記述スタイル( (!p) と (p == NULL) 等)は個々人
の好みが大きく異なっているので、そういった問題のない慣用表現を先
にまとめてみるのもアリかもしれないと思いました。

以下のように、頻出のコード表現について定型とそうすべき理由を書き
連ねておき、特に理由がない限りはそれに従うという形はどうでしょう
か?

SigSchemeでの井上さんとの議論が発端ですが、uimまでカバーしても問
題ないんじゃないかと思います。


doc/IDIOMS:

* Traversing a list

  for (rest = lst; !NULLP(rest); rest = CDR(rest)) {
    elm = CAR(rest);
    <code body>
  }

  - The element extraction "elm = CAR(rest)" is not performed in the expression
    part of 'for', but in the block. It is intended that a null list can be
    applied to the idiom without adding special handlings for it.

  - 'lst' is the target list. It varies to 'args', 'procs', 'names' and so on
    in accordance with the circumstances.

  - 'rest' indicates that it points to the tail part of the list through the
    traverser.

    If you want to indicate which rest of, append the original list name such
    as 'rest_args'. Don't omit the 'rest' prefix since it is required to
    indicate the variable's role in the idiom.

    Direct overwriting of the list such as "args = CDR(args)" should be avoided
    if no significant reason exist, because it may be misunderstood as pointing
    to the original list always.

  - 'elm' indicates that the object is extracted from a list.

    It should not arbitrarily be named such as 'obj' or 'val' since the names
    indicate neither its role in the idiom nor its content specification.

    If any confusion or misunderstanding will not be involved around the code,
    it may be named reflecting its content, such as "arg = CAR(rest_args)" or
    "sym = CAR(rest)". Select better name case by case.

-------------------------------
ヤマケン yamak****@bp*****



Anthy-dev メーリングリストの案内
Back to archive index