-
Notifications
You must be signed in to change notification settings - Fork 99
Coding Standards
trentmeester edited this page Dec 16, 2011
·
4 revisions
- Lines of code may not exceed 80 characters, except when formatting text for display purposes.
a) A good example of the exception to this rule resides within file tnvme.cpp in function Usage(). - CamelCapitalization (CamelCaps) is defined as capitalizing the first letter of each word, except...
a) If the word is an abbreviation...
i) it should be in capitals....
* NVM, DRAM, CO, SQ, CQ, CE, etc
* ASQSupport, SRAMAllocator, etc
ii) it should not be capitals when it is the leading part of a local variable or parameter variable
* sramLocalVariable
b) No underscores are used. - Global variables are CamelCaps and must start with the lower case letter 'g'
a) gGlobalVariable, gSRAMGlobalVariable - Constants and #defines are all capital letters
a) Each word can be separated by an '_'; Example: MAX_CHAR_PER_LINE_DESCRIPTION
b) Each word can be adjacent to the prior; Example: APPNAME - Indentation
a) tabs are strictly never allowed anywhere and are replaced with 4 space characters - Directory names
a) Are CamelCaps
b) Directories naming a group must be prepended with "Grp"
i) GrpBasicInit, GrpRegisters
- All functions names are CamelCaps
a) ThisIsAGlobalFunction(), SRAMAllocatorFunc(), ThisIsAMemberFunction() - Function definitions are allowed to be coded on the same line.
a) uint16_t GetCqId() { return mCqId; } - Function body braces are must be on their own line, and the return type is also on its own line...
void
MyFunction(int parameterVariable)
{
// Comment
}
- All local variables are CamelCaps but must start with lower a lower case letter
a) localVariable, sramLocalVariable - Function parameters are CamelCaps but must start with lower a lower case letter
a) parameterVariable, sramParameterVariable
- The body of multi-lined flow control statements must have the opening brace on the same line
if (myLocalVariable == 4) {
// Comment
} else if (funcParamVar > 0) {
// Comment
}
switch (localVar) {
case VALUE1:
break;
default: // default handling is required always
break;
}
for (int i=0; i>=VALUE1; i++) {
// 1) Spaces between the above operators are optional
// 2) Spaces after the ';' are required
}
- The general layout of a class is:
/*
* Class level comment, must exist and provide reason for classes existence. Terse comments of the type
* "It provides low level support" could be 100% correct, but are also 100% useless and are thus not allowed.
*/
class ClassName : public BaseClass, public BaseClass // Spaces around all is required, except ',' character
{
public:
/**
* Non-default constructors must be commented
* @param constructParamVar This must be commented
*/
Constructor(int constructParamVar);
/**
* Commenting destructors are always optional
*/
virtual ~Destructor();
protected:
/**
* Member function comment is mandatory except it is resides with a child test class, then it is optional.
* Terse comments of the type "It provides low level support" could be 100% correct, but are also 100%
* useless and are thus not allowed.
* @param funcParamVariable This is mandatory if the member function is being commented
* @return This is mandatory if the function is being commented
*/
bool MemberFunction(int funcParamVariable); // No spaces after or before '(' and ')' characters
private:
Constructor();
/// A member variable commenting is optional
int mMemberVariable;
};
- Class member variables are CamelCaps and must start with the lower case letter 'm'
a) mMemberVariable, mSRAMMemberVariable
- File names
a) Are CamelCaps and must start with a lower case letter
i) subject.h, testDescribe.cpp b) That name a group class must be prepended with "grp" i) grpBasicInit.cpp - The layout of a header file is:
/* * Copyright (c) 2011, Intel Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _FILENAME_H_ // FILENAME needs to be replace with the actual name of this file #define _FILENAME_H_ // Include files // typedefs, #defines, enumeration or structure definitions, and namespace references // class definitions #endif
- The layout of a source file is:
/* * Copyright (c) 2011, Intel Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Include files // typedefs, #defines, enumeration or structure definitions, and namespace references // class implementation