From c8889e656343994d147a2f46c215f861b4034359 Mon Sep 17 00:00:00 2001 From: "Kevin P. Fleming" Date: Thu, 19 May 2005 04:31:02 +0000 Subject: 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: https://origsvn.digium.com/svn/asterisk/trunk@5733 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- doc/CODING-GUIDELINES | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'doc/CODING-GUIDELINES') 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. -- cgit v1.2.3