メモ
・一貫性のあるコードにする
・似ているコードは似ているように見せる
・関連するコードはまとめてブロックにする
例
以下の点に注意する
- 改行位置
- 縦の整列
- 段落分け
- 順序
- HTMLのinputフィールドと同じ並び
- 重要度順
- データベースのカラムの順番
以下のコードは、
*改行に一貫性がない
*縦に整列していない
*段落で分かれていない
*順序が適切でない
public class PerformanceTester {
public static final TcpConnectionSimulator cell = new TcpConnectionSimulator(
500, /* Kbps */
80, /* millisecs latency */
200, /* jiter */
1 /* packet loss % */);
public static final TcpConnectionSimulator t3_fiber =
new TcpConnectionSimulator(
45000, /* Kbps */
10, /* millisecs latency */
0, /* jiter */
0 /* packet loss % */);
public static final TcpConnectionSimulator wifi = new TcpConnectionSimulator(
100, /* Kbps */
400, /* millisecs latency */
250, /* jiter */
5 /* packet loss % */);
}
修正後
public class PerformanceTester{
// TcpConnectionSimulator(throughput, latency, jitter, packet_loss)
// [Kbps] [ms] [ms] [%]
public static final TcpConnectionSimularor wifi =
new TcpConnectionSimulator(500, 80, 200, 1);
public static final TcpConnectionSimulator t3_fiber =
new TcpConnectionSimulator(45000, 10, 0, 0);
...
}
コメントは1行にまとめ長いコードを改行し一貫性を保つ。
また、配列や引数にどんな値が入っているかをコメントに書いておく。