aboutsummaryrefslogtreecommitdiffstats
path: root/doc/CODING-GUIDELINES
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-19 04:31:02 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-19 04:31:02 +0000
commit10d27ab9b433cfeae5d075f9119649b6897119a3 (patch)
tree325359167401a2a23ed74722c218e63834b30fab /doc/CODING-GUIDELINES
parentd64a37edcde332108f76cb6667848244f9dc920d (diff)
add IAXPEER function (bug #4310, with minor formatting and doc changes)
add note to CODING-GUIDELINES about minimizing indentation in function bodies git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5733 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'doc/CODING-GUIDELINES')
-rwxr-xr-xdoc/CODING-GUIDELINES25
1 files changed, 24 insertions, 1 deletions
diff --git a/doc/CODING-GUIDELINES b/doc/CODING-GUIDELINES
index 41147fb5a..01a38d6f2 100755
--- a/doc/CODING-GUIDELINES
+++ b/doc/CODING-GUIDELINES
@@ -34,7 +34,7 @@ When reading integer numeric input with scanf (or variants), do _NOT_ use '%i'
unless specifically want to allow non-base-10 input; '%d' is always a better
choice, since it will not silently turn numbers with leading zeros into base-8.
-Roughly, Asterisk coding guidelines are generally equivalent to the
+Roughly, Asterisk code formatting guidelines are generally equivalent to the
following:
# indent -i4 -ts4 -br -brs -cdw -cli0 -ce -nbfda -npcs -npsl foo.c
@@ -87,7 +87,30 @@ for (x=0;x<5;x++) {
}
}
+Don't build code like this:
+if (foo) {
+ .... 50 lines of code ...
+} else {
+ result = 0;
+ return;
+}
+
+Instead, try to minimize the number of lines of code that need to be
+indented, by only indenting the shortest case of the 'if'
+statement, like so:
+
+if !(foo) {
+ result = 0;
+ return;
+}
+
+.... 50 lines of code ....
+
+When this technique is used properly, it makes functions much easier to read
+and follow, especially those with more than one or two 'setup' operations
+that must succeed for the rest of the function to be able to execute.
+
Make sure you never use an uninitialized variable. The compiler will
usually warn you if you do so.