- Author
- Jamoma, Timothy Place, Nathan Wolek, Trond Lossius
Variables
- Declare all variables on separate lines.
- If a variable is assigned immediately, then give it a default value in the declaration.
- Prefer explicit types, e.g. TTObjectPtr rather than TTObject*.
- User tabular formatting, as mentioned in the section "Whitespace"
Functions
Functions always appear:
- With the return type on the same line as the function name
- With the arguments on the same line as the function name, unless they dont fit. In this case they follow in tabular format below the first argument name.
- The open curly brace is on the line below the function name – not the same line.
- The closing curly brace is always on its own line
{
return this->directory;
}
- Whitespace between two functions should generally be two blank lines.
- There should never be two consecutive blank lines within a function.
Arguments
Prefer passing arguments as TTValueRef or const TTValueRef.
Whitespace
Multiple lines of similar function calls, similar definitions, should prefer tabular style formatting (which is to say, things are lined up in columns). This makes it faster to see the variant information between the lines, and also to edit multiple lines simultaneously using an editor such as TextMate.
Naming Conventions
Macros should be all upper case, words divided by underscores
Variables
- CamelCase.
- Variable names begin with lower-case letters
- Class Member variables begin with 'm'
- Constants begin with a 'k'
- Globals begin with 'g'
- Statics begin with 's'
- member method names begin with lower-case letters
- Classes or Global scope functions beggin with upper-case letters.
- Library functions begin with 'TT', non-library functions do not.
Casting
- Be wary of casting if the problem/warning can be avoided in another way.
- Readability is the most important thing. So we dont always use the crazy C++ casting stuff...
- Prefer C++ Style
int(someValue)
casts to (int)someValue
casts.
Constructors
- for TTObject subclasses, use the appropriate macro (such as TT_OBJECT_CONSTRUCTOR) to implement the function signature correctly
- prefer initializers to assigning values
- initializers should be indented one tab
Doxygen documentation
Documentation of Jamoma's C++ source code is generated using specific annotations that can be extracted by Doxygen. In addition to the general features of Doxygen, we have developed several style conventions for Jamoma to provide consistency and ensure readability.
Header and source code files
At the top of header files seven key tags are necessary for consistent Doxygen documentation across Jamoma. The header files for TTSampleMatrix.h and TTBuffer.h can serves as examples for how to do this.
- @file - identifies the file as a module that Doxygen should process
- @ingroup - contains a tag representing the library or extension
- @brief - single sentence that describes what the module does, ideally starting with a verb
- @details - longer description that may be several sentences
- @seealso - a list of related modules that you wish to link to
- @authors - persons who have made significant conrtibutions to the module
- @copyright - a failure consistent BSD licences description
This information is also to be copied across to the .cpp source file.
Classes
In the header file documentation of classes is typically expected to contain the following information.
- @brief - single sentence that describes what the module does, ideally starting with a verb
- @details - longer description that may be several sentences (where relevant)
- @seealso - a list of related modules that you wish to link to (where relevant)
Because header files in the Jamoma Core typically document a single class, it is possible to make use of Doxygen's special commands for copying comments, thereby keeping our comments DRYer. These commands allow us to maintain a single set of brief and detailed comments at the top of our header files, but then apply those comments to both the header file and class definition. The following example from TTValue.h demonstrates these tags in use:
class TTValue :
public TTElementVector {
Variables
Each variables is provided with a brief description of its purpose, as in this example:
Methods
- @brief - single sentence that describes what the method does, ideally starting with a verb
- @details - longer description that may be several sentences
- @param - each argument to the method is documented
- @return - Documents the value returned by the method
- @seealso - a list of related modules that you wish to link to
Example:
If a given method is overloaded, it is possible to make use of Doxygen's overload command. Whenever this command is used, a full set of Doxygen comments should be placed on the first version of the method, followed by the overload tag for each subsequent version. Similar to the copy commands, this results in comments that are DRYer.
Common declarations
Jamoma's documentation attempts to gather common declaration types together using Doxygen's grouping features. To add these items to established groups, annotations should make use of the ingroup tag in addition to providing a suitable description. The following subsections provide examples of the ingroup tag in use.
Constants
Constants need to be indicated as being part of the const
group.
Enumerations
Enumerations need to be indicated as being part of the enums
group. The list of enumerations, as well as each of its values, are described:
Bit masks
Bitmasks need to be indicated as being part of the bitmasks
group. The list of bitmasks, as well as each of its values, are described:
kTTAudioGraphFlagsNone = 0x00,
};
Typedefs
Typedefs need to be indicated as being part of the typedefs
group:
Macros
Macros need to be indicated as being part of the macros
group:
#define INDEX_OF_COMPONENT_FIRSTBYTE(i, j) \
{ \
(i * mColumnCount + j) * mComponentStride \
}