Skip to Content
リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック
book

リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック

by Dustin Boswell, Trevor Foucher, 角 征典
June 2012
Beginner to intermediate content levelBeginner to intermediate
260 pages
2h 35m
Japanese
O'Reilly Japan, Inc.
Content preview from リーダブルコード ―より良いコードを書くためのシンプルで実践的なテクニック

6章コメントは正確で簡潔に

前章では、何をコメントに書くべきかを説明した。本章では、どうすればコメントを正確で簡潔に書けるかを説明する。

コメントを書くのであれば、正確に書くべきだ(できるだけ明確で詳細に)。また、コメントには画面の領域を取られるし、読むのにも時間がかかるので、簡潔なものでなければいけない。

[Tip]

鍵となる考え

コメントは領域に対する情報の比率が高くなければいけない。

これからそのやり方を見ていこう。

6.1 コメントを簡潔にしておく

以下は、C++の型定義につけたコメントの例だ。

// intはCategoryType。
// pairの最初のfloatは'score'。
// 2つめは'weight'。
typedef hash_map<int, pair<float, float> > ScoreMap;

どうして3行も使って説明しているのだろう? これなら1行で説明できないだろうか?

// CategoryType -> (score, weight)
typedef hash_map<int, pair<float, float> > ScoreMap;

3行分の領域が必要なこともあるだろう。でも、ここには必要ない。

6.2 あいまいな代名詞を避ける ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

リーンエンタープライズ ―イノベーションを実現する創発的な組織づくり

リーンエンタープライズ ―イノベーションを実現する創発的な組織づくり

Jez Humble, Joanne Molesky, Barry O'Reilly, 角 征典, 笹井 崇司, Eric Ries

Publisher Resources

ISBN: 9784873115658Other