[Groonga-mysql-commit] mroonga/mroonga [fix-for-visual-studio] doc coding-style: add about NULL in condition

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Oct 4 10:39:03 JST 2012


Kouhei Sutou	2012-03-15 18:11:04 +0900 (Thu, 15 Mar 2012)

  New Revision: 3d65ee6975a21b499da99b53f362df76f15fc058
  https://github.com/mroonga/mroonga/commit/3d65ee6975a21b499da99b53f362df76f15fc058

  Log:
    doc coding-style: add about NULL in condition

  Modified files:
    doc/source/developer/coding_style.rst

  Modified: doc/source/developer/coding_style.rst (+15 -0)
===================================================================
--- doc/source/developer/coding_style.rst    2012-03-15 18:06:22 +0900 (c53e6ea)
+++ doc/source/developer/coding_style.rst    2012-03-15 18:11:04 +0900 (ea334e4)
@@ -452,3 +452,18 @@ bool型を用いる
     boolean is_searching = true;
     if (is_searching == false) { ... }
 
+``NULL`` と比較しない
+^^^^^^^^^^^^^^^^^^^^^^
+
+``NULL`` かどうかを条件式に使う場合は ``value == NULL`` ではなく ``!value`` というように書く。多くの言語で ``NULL`` に相当する値(たとえばLispの ``nil`` )は偽を表すため、明示的に ``NULL`` と比較しなくても意図は伝わるからである。
+
+よい例:
+
+    char *name = NULL;
+    if (!name) { ... }
+
+悪い例( ``NULL`` と比較している):
+
+    char *name = NULL;
+    if (name == NULL) { ... }
+
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-mysql-commit mailing list
Back to archive index