Clean Code vs. プログラミングのセオリー

他の積読本を全部後回しにして読み始めたけど、結構読みやすくていい感じ。
この本の方が、「セオリー」を名乗るにふさわしい内容だと思う。
プログラミングのセオリーで「いい」とされていることが Clean Code で「悪い」とされていることもあるから、「セオリー読んだけどどこが間違ってるのか分からなかったよ」な人はこの本を読めばいいと思う。
例えば、閉じ括弧の後のコメントについて、セオリーでは「コメントの書き方、3つのテクニック」として、

for (i = 0; i < MAX; i++)
{
    if (a > b)
    {
        // 何らかの処理
    } // end of if
} // end of for
プログラミングのセオリー

こんなコードを紹介してるんだけど、Clean Code では、

Sometimes programmers will put special comments on closing braces, as in Listing 4-6. Although this might make sense for long functions with deeply nested structures, it serves only to clutter the kind of small and encapsulated functions that we prefer. So if you find yourself wanting to mark your closing braces, try to shorten your functions instead.

Listing 4-6
wc.java

public class wc {
  public static void main(String[] args) {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String line;
    int lineCount = 0;
    int charCount = 0;
    int wordCount = 0;
    try {
      while ((line = in.readLine()) != null) {
        lineCount++;
        charCount += line.length();
        String words[] line.split("\\W");
        wordCount += words.length;
      } //while
      System.out.println("wordCount = ", + wordCount);
      System.out.println("lineCount = ", + lineCount);
      System.out.println("charCount = ", + charCount);
    } // try
    catch (IOException e) {
      System.err.println("Error:" + e.getMessage());
    } //catch
  } //main
}
Clean Code

ばっさり。
上の英文に拒絶反応が起こらないようなら、ぜひ読んでみるといいと思うよ。


Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)

Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin Series)