[Asterisk-cvs] asterisk/doc CODING-GUIDELINES,1.10,1.11
kpfleming at lists.digium.com
kpfleming at lists.digium.com
Thu May 19 00:25:59 CDT 2005
Update of /usr/cvsroot/asterisk/doc
In directory mongoose.digium.com:/tmp/cvs-serv10242/doc
Modified Files:
CODING-GUIDELINES
Log Message:
add IAXPEER function (bug #4310, with minor formatting and doc changes)
add note to CODING-GUIDELINES about minimizing indentation in function bodies
Index: CODING-GUIDELINES
===================================================================
RCS file: /usr/cvsroot/asterisk/doc/CODING-GUIDELINES,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- CODING-GUIDELINES 15 May 2005 23:26:45 -0000 1.10
+++ CODING-GUIDELINES 19 May 2005 04:31:02 -0000 1.11
@@ -34,7 +34,7 @@
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 @@
}
}
+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.
More information about the svn-commits
mailing list