summaryrefslogtreecommitdiff
path: root/docs/CODE_STYLE.md
diff options
context:
space:
mode:
authorSteve Holme <steve_holme@hotmail.com>2016-03-20 11:51:11 +0000
committerSteve Holme <steve_holme@hotmail.com>2016-03-20 11:51:11 +0000
commiteba1b3099fce4e81260285f7cc68caf664aa8ea8 (patch)
tree4fea4c99ab9accd4ec00f7a5d2a9ec12e57b5072 /docs/CODE_STYLE.md
parentf046ac48d67c8597a7d6d8dff835436f9d628da2 (diff)
downloadcurl-eba1b3099fce4e81260285f7cc68caf664aa8ea8.tar.gz
CODE_STYLE: Use boolean conditions
Rather than use TRUE, FALSE, NULL, 0 or != 0 in if/while conditions. Additionally, corrected some example code to adhere to the recommended coding style.
Diffstat (limited to 'docs/CODE_STYLE.md')
-rw-r--r--docs/CODE_STYLE.md18
1 files changed, 16 insertions, 2 deletions
diff --git a/docs/CODE_STYLE.md b/docs/CODE_STYLE.md
index 8cfb26e6f..d77fc4476 100644
--- a/docs/CODE_STYLE.md
+++ b/docs/CODE_STYLE.md
@@ -101,6 +101,20 @@ between the keyword and the open parenthesis. Like this:
/* loop forever */
}
+## Use boolean conditions
+
+Rather than test a conditional value such as a bool against TRUE or FALSE, a
+pointer against NULL or != NULL and an int against zero or not zero in
+if/while conditions we prefer:
+
+CURLcode result = CURLE_OK;
+
+result = do_something();
+if(!result) {
+ /* something went wrong */
+ return result;
+}
+
## No assignments in conditions
To increase readability and reduce complexity of conditionals, we avoid
@@ -112,7 +126,7 @@ assigning variables within if/while conditions. We frown upon this style:
and instead we encourage the above version to be spelled out more clearly:
ptr = malloc(100);
- if(ptr == NULL)
+ if(!ptr)
return NULL;
## New block on a new line
@@ -164,7 +178,7 @@ depending on a build-time conditional:
#ifdef HAVE_MAGIC
void magic(int a)
{
- return a+2;
+ return a + 2;
}
#else
#define magic(x) 1