Coding style

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(File name conventions)
(File organisation)
Line 9: Line 9:
 
The main parts of Yate are in directories:
 
The main parts of Yate are in directories:
  
* clients
+
* clients - files for Yate's Client interface
 
* conf.d - the configuration files in Yate
 
* conf.d - the configuration files in Yate
* docs
+
* docs - documentation of Yate's API
* engine
+
* engine - the Engine classes
 
* libs - the main libraries
 
* libs - the main libraries
* modules
+
* modules - Modules classes:
* packing
+
:* routing modules
* share
+
:* signaling modules
* tools
+
:* script language bindings
* windows
+
:* CDR modules
 +
* packing  
 +
* share - here you can find scripts directory that contain the most important library that communicates with Yate written in PHP and Python
 +
* tools - some useful bash scripts
 +
* windows - files for Yate's functionality in Windows
  
 
===File name conventions===
 
===File name conventions===

Revision as of 17:18, 21 November 2012

Bellow it can be read about the coding style rules to preserve Yate's uniformity of the source code. You can find out about the files name conventions or comments style and a few tips for scripts written in PHP.
Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier.

Contents

C++ code

File organisation

The main parts of Yate are in directories:

  • clients - files for Yate's Client interface
  • conf.d - the configuration files in Yate
  • docs - documentation of Yate's API
  • engine - the Engine classes
  • libs - the main libraries
  • modules - Modules classes:
  • routing modules
  • signaling modules
  • script language bindings
  • CDR modules
  • packing
  • share - here you can find scripts directory that contain the most important library that communicates with Yate written in PHP and Python
  • tools - some useful bash scripts
  • windows - files for Yate's functionality in Windows

File name conventions

This will keep the code clean and readable.

  • File names must have .cpp extension, include files must have .h
  • All header file names must be lower case
  • Module file name is always lower case
  • Engine file names are mixed case just like class names meaning first letter is upper case and the others lower case

Comments

  • Use exclusively C++ style comments in code definition
  • Use C style comments in declarations only to provide documentation to kdoc or Doxygen
  • Don't use comments to temporarily disable more than one line of code, use #if 0 ... #endif instead
  • At the end of source code files please add settings for those that use vi or vim as editor: /* vi: set ts=8 sw=4 sts=4 noet: */

Templates

  • Avoid templates if at all possible, even those from standard template library (STL)
They will lead to increase compile times and memory usage, resulting in excessively large executables. Second, almost all compilers produce confusing, unhelpful error messages when errors are detected in template code. This can make templates difficult to develop.
  • Only use fully inline template classes and functions
Let's say that you have 2 classes with the same methods, the only difference are the types of objects with who they operate, then it's better to use inline templates classes. These concepts save program space and memory because the class is stored only in one place (usually in .h file) and is only executed when it is instantiated. Also it is easier to maintain.

PHP code

The style for writing external PHP modules and IVRs is very similar to the one for C++ code.

  • Always require_once("libyate.php") towards the start of any module or library
  • Never put anything outside the <? ... ?> tags
  • Properly declare static methods with the static keyword as required by PHP5 or higher
  • Use Yate::Output to send output to console or log file
  • Use Yate::Debug to send debugging output to console or log file, this can be turned on or off by providing a boolean argument


See also

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers