0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

リーダブルコードを読んでの個人メモ(2)

0
Posted at

メモ

・一貫性のあるコードにする
・似ているコードは似ているように見せる
・関連するコードはまとめてブロックにする

以下の点に注意する

  • 改行位置
  • 縦の整列
  • 段落分け
  • 順序
  • 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行にまとめ長いコードを改行し一貫性を保つ。
また、配列や引数にどんな値が入っているかをコメントに書いておく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?