Coding Guidelines

From FreeSWITCH Wiki
Jump to: navigation, search

Contents

Introduction

When submitting patches or otherwise adding code to the project please follow some basic coding guidelines.
Most .c files will have this information at the very end for your reference:

/* For Emacs:
 * Local Variables:
 * mode:c
 * indent-tabs-mode:t
 * tab-width:4
 * c-basic-offset:4
 * End:
 * For VIM:
 * vim:set softtabstop=4 shiftwidth=4 tabstop=4
 */

Structures and Curly Braces

Please observe these conventions:

  • Tabs are preferred over spaces, tab-width is four characters
  • Always use curly braces for conditional statements *unless* they are on the same line and are very short
  if (foo) printf("blah\n");
  • Always space after if
if (foo) {

}
  • Nested else
if (foo) {
...
} else if (bar) {

} else {

}
  • Function definitions with newline
int foo (int arg)
{
...
}

Comments

Please use comments appropriate to the language you are using.

C

Use /* and */ when adding comments in C programs. Please don't use // for comments in C programs.

C++

Use the // style for C++ programs

Lua

Lua has two styles of comments:

  • Single Lines
-- This is a single line comment
  • Multiple Lines
--[[
All of this
Is commented
]]

See Also