diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-02-26 18:40:26 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-02-26 18:40:26 +0000 |
commit | 14f999674368002d851d26b5f52db0ce642c8daf (patch) | |
tree | ebe7c6a860e5e58c1f54e378ebe9279c3e2ce81c /doc | |
parent | 5485ea4bccde77f6e16381cd51954a7165fa5dee (diff) |
1) Make braces mandatory for if/for/while, even around single statements.
2) Revise the argument parsing section, showing use of the standard macros.
3) Fix a typo.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@104176 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'doc')
-rw-r--r-- | doc/CODING-GUIDELINES | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/doc/CODING-GUIDELINES b/doc/CODING-GUIDELINES index 1b53402ac..af48159bc 100644 --- a/doc/CODING-GUIDELINES +++ b/doc/CODING-GUIDELINES @@ -226,11 +226,15 @@ for (x = 0; x < 5; x++) instead do: for (x = 0; x < 5; x++) { if (foo) { - if (bar) + if (bar) { baz(); + } } } +- Always use braces around the statements following an if/for/while construct, +even if not strictly necessary, as it reduces future possible problems. + - Don't build code like this: if (foo) { @@ -376,15 +380,15 @@ you intend to parse the incoming data string. mydata = ast_strdupa(data); -- Separating arguments to dialplan applications and functions -Use ast_app_separate_args() to separate the arguments to your application -once you have made a local copy of the string. +- Use the argument parsing macros to declare arguments and parse them, i.e.: -- Parsing strings with strsep -Use strsep() for parsing strings when possible; there is no worry about -'re-entrancy' as with strtok(), and even though it modifies the original -string (which the man page warns about), in many cases that is exactly -what you want! + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(arg1); + AST_APP_ARG(arg2); + AST_APP_ARG(arg3); + ); + parse = ast_strdupa(data); + AST_STANDARD_APP_ARGS(args, parse); - Create generic code! If you do the same or a similar operation more than one time, make it a @@ -463,7 +467,7 @@ in having code like this: else newstr = NULL; -However, the ast_strdup and ast_strdup functions will happily accept a NULL +However, the ast_strdup and ast_strdupa functions will happily accept a NULL argument without generating an error. The same code can be written as: newstr = ast_strdup(str); |