C++ Coding Guidelines General * Use common sense, be consistent, and retain the existing style in modifications * Strive for cross platform consistency and do not use Hungarian notation or other single platform conventions * For working with Windows classes it is necessary to use multiple inheritance and Windows defined types so go with the flow as needed for consistent looking code * Similar or identical functionality may be implemented in Java and/or Objective C so strive for language agnostic design and coding constructs * Method parameters should be ordered with inputs then outputs * Floating point constants should always use at least one digit on both sides of the decimal point * Use whitespace and alignment to improve readability * Class and method header comments should follow the JavaDoc conventions, exported interfaces must be well documented, use your judgment on internal interfaces * Use // TODO (name) description comments for incomplete code (// FIXME and // @todo can also be used with Eclipse) * All code must compile with no Warnings on any platform and pass all static and runtime checking, adding a pragma or other suppression with a comment is acceptable * Standard build targets: all, clean, compile, data, docs, execs, libexecs, libs, unittest * Have the copyright notice Copyright (c) IOnU Security Inc. in the header comment of all source files Files * File names should be all lower case with ‘_’ separators and use .h and .cpp suffixes * Header files must have include guards * Header files should never contain using declarations or directives * Include statements should be grouped and only be at the top of the file * All classes should be defined in .h files (test only classes excepted) and implemented in .cpp files Naming * Use meaningful and consistent names so the reader understands from the code * Named constants and enumeration values are all upper case with ‘_’ separators * Class and Type names use mixed case and begin with upper case * Variables are nouns and use mixed case * Methods are verbs and use mixed case * Names representing namespaces are all lower case * Template types use a single upper case letter * Global variables should always use the :: operator * Private class variables use an ‘_’ suffix * Plural form should be used for names representing collections * The prefix ‘n’ should be used for names representing the number of items * The prefix is should be used for all Boolean variables and methods * Abbreviations should be avoided, except where the abbreviation is the common form, never use both * Use symmetric and standard names for methods (i.e. add/remove, create/destroy, insert/delete) * Exception classes should use the suffix Exception and we may want to avoid exceptions * The name of the object is implicit so don’t repeat it in method names C++ * All C++ code should be in the ionu namespace * Using declarations are preferred over using directives unless you actually use everything using boost::shared_ptr; // not - using namespace boost; * Class definitions should be ordered from public to private * All classes must provide a default constructor and should only provide a copy constructor and assignment operator when necessary * Use the keyword explicit for constructors with one argument to avoid implicit conversions * The prefix get/set must be used for direct access to member variables * Use for explicitly sized integers * Use the C++ static_cast<>() or dynamic_cast<>() not the old C cast which uses the same syntax for conversion and cast (e.g. (int)7.9 and (int)abcd). * Variables should be initialized as close to their definition as possible * Pointers and references should not have special names and the reference symbol is on the type MyCar* car; * Implicit test for ‘0’ should only be used with Boolean variables and use NULL (or nullptr when all compilers support C++11) for pointer initialization and checking if (isMyCar) if (count == 0) MyCar* car = NULL; // or = nullptr; * Interface only classes should be tagged with Interface suffix, and these classes have only pure virtual methods, no non-static members, a protected constructor (if one is needed), and a virtual destructor. * Avoid multiple inheritance unless you have to use it, and then only one of the parent classes can be a non Interface class Layout Indentation should be 3-4 spaces, conventional operators surrounded by a space, space after comma, semicolon, and parens