User Tools

Site Tools


iotivity_coding_standards

The IoTivity Coding Standards provide guidelines for how to write code within the IoTivity project. Code committed to the IoTivity project should follow the standards where appropriate. No coding standard can determine what is best in every situation, however developers deviating from the standard should be able to justify why the standard is not applicable.

IoTivity builds and runs on several different platforms using different languages. Each language has its own language standard to better follow the idioms and conventions developers using that language expect.

C++

IoTivity C++ code runs on all platforms. The coding standard is divided into syntactic and semantic parts. The syntactic guidelines provide a clean consistent look for the code. The semantic parts are intended to be advice for writing safe and robust code. The current copy is available on the IoTivity C++ Coding Standards page.

In addition, developers are encouraged to read the best practices in C++ Coding Standards, Sutter & Alexandrescu (also available electronically Safari Subscription, which is included with ACM membership and available through many corporate digital library subscriptions).

Configuring Eclipse

To configure Eclipse to automatically follow the IoTivity style guidelines:

  1. On the Menu bar go to Window > Preferences
  2. In the left pane click C/C++ > Code Style > Formatter
  3. On the right pane click Import button
  4. Choose iotivity_cpp_style.xml from iotivity/tools/style/iotivity_cpp_style.xml
  5. Click Apply

Configuring Visual Studio

To configure Visual Studio to automatically follow the IoTivity style guidelines:

  1. Open Visual Studio. Click Tools on the menu bar. Then choose Options
  2. On the left pane of the Options dialog click “AStyle Formatter”
  3. In the right pane click the Export/Import tab.
  4. Next hit the Import button to import the file iotivity\tools\style\iotivity_cpp_astyle.cfg

Configuring Emacs

Tune your .emacs with those changes :

(setq-default indent-tabs-mode nil)

Configuring Atom

A formatter that uses Astyle in Atom is available. Install formatter and formatter-astyle from your settings view. You need to have astyle installed in the system as well. To finish the setup, create an .astylrc in the project root based the settings from tools/style/astyle-cpp-format.sh - leave out the shell-style syntax, and the recursive option.

Bulk C++ Formatting

These instructions describe how to reformat all of the C++ code using the Artistic Style tool.

  1. Install Artistic Style using the instructions from http://astyle.sourceforge.net (note Linux distributions probably already have astyle in their package repository)
  2. Run ${IOTIVITY}/tools/style/astyle-cpp-format.sh in the top-level directory containing files to be reformatted, where ${IOTIVITY} is the path to the iotivity repository. The script runs the formatter on all .cpp and .h files in the current directory and all subdirectories, recursively.
  3. The formatting process will create backup copies of the original file. All back up files have the .orig extension. To move the *.orig files run ${IOTIVITY}/tools/style/astyle-clean-cpp-format.sh. The script places all of the .orig file in the astyle_backup folder.

Java

IoTivity uses the Android Java Coding Standard for Java code.

Configuring Eclipse

To configure the Eclipse IDE to automatically follow the IoTivity style guidelines, please do the following:

  1. On the Menu bar go to Window > Preferences
  2. In the left pane click Java > Code Style > Formatter
  3. On the right pane click Import button
  4. Choose ccf_cpp_style.xml from iotivity-core/doc/style/iotivity_java_style.xml
  5. Apply

iOS Objective-C

C#

Python

Informal: All of the scons scripts are in Python. This includes SConstruct, SConscript and *.scons files. At this time, the project has not formally adopted a coding standard for these files, so the use of Python's own style guid PEP8 is only a recommendation. Pertinent suggestions include 4-space indents, no tabs, single spaces surrounding operators ( = == + and so on); no spaces around = sign for keyword arguments. There are code formatting tools that will provide PEP8 compliance.

iotivity_coding_standards.txt · Last modified: 2017/04/18 14:45 by Mats Wichmann