Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Files may contain items in the following order. 

File Banner

Code Block
/*

...


 * If not stated otherwise in this file or this component's Licenses.txt file the

...


 * following copyright and licenses apply:

...


 *

...


 * Copyright

...

 2020 RDK Management

...


 *

...


 * 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.

...


*/

File Guards

In all header files, do the following (using the exact file names) to prevent an header file from being included more than once: For example in C do the following


Code Block
#ifndef FILENAME_H

...



#define FILENAME_H

...



// File content

...



#endif // Last line of code in file


This is to avoid multiple definitions, and to ensure that the ifndef checks a unique identifier.

...

Identifiers should not exceed 31 characters.

Data Type

Prefix

Sample Variable Names

int32

i

iSequenceNo

unsigned int32

ui

uiSequenceNo

int16

n

nSequenceNo

unsigned int16

un

unSequenceNo

BOOL

b

bTransmitted

Char

ch

chSequenceNo

unsigned char

uch

uchSequenceNo

long

l

lSequenceNo

unsigned long

ul

ulSequenceNo

enumerated data type

e

eCapabilityMode

Arrays

a

int32 aiSequenceNo[10]     etc

Pointers

p

int32 piSequenceNo      etc …

Globals

g

giSequenceNo,  gpTimer etc

Typedef

All the type names shall be suffixed with _t.

Typedef struct _IPAddessInfo

{

}IPAddressInfo_t;

Statements

Only one statement should exist per line.

...

Conditional statements found in if, while, do etc. should be explicit based on the data type of variable tested for.

for e.g. in C++


if ( value == 0 // right
{
doso() ;
}
if ( !value ) //wrong
{
dontdoso();
}


Inaccessible code should be avoided. Care should be taken when using GOTO or return statement .

...

The null body of a "for" or "while" loop should be alone on a line and commented so that it is clear that the null body is intentional and not missing code.


while (*dest++ = *src++)
{
/* VOID */
}


All control statements should be followed by an indented code block enclosed with braces, even if it only contains one statement. This makes the code consistent and allows the block to be 
easily expanded in the future.

For example in C++ use :


if ( value == 0 )
// right
doSomething();
}
if ( value == 0 ) doSomething(); // wrong - no block, not indented
if (value == 0)
doSomething(); // wrong - no block


Automatically Generated Code

...

    • If you're editing code, take a few minutes to look at the code around you and determine its style.
    • If they use spaces around all their arithmetic operators, you should too.
    • If their comments have little boxes of hash marks around them, make your comments have little boxes of hash marks around them too.
    • The point of having style guidelines is to have a common vocabulary of coding so people can concentrate on what you're saying rather than on how you're saying it.
    • If code you add to a file looks drastically different from the existing code around it, it throws readers out of their rhythm when they go to read it. Avoid this.

Naming

Type

Public

Internal

Packageslower_with_under
Moduleslower_with_under_lower_with_under
ClassesCapWords_CapWords
ExceptionsCapWords
Functionslower_with_under()_lower_with_under()
Global/Class ConstantsCAPS_WITH_UNDER_CAPS_WITH_UNDER
Global/Class Variableslower_with_under_lower_with_under
Instance Variableslower_with_under_lower_with_under (protected) or __lower_with_under (private)
Method Nameslower_with_under()_lower_with_under() (protected) or __lower_with_under() (private)
Function/Method Parameterslower_with_under
Local Variableslower_with_under

Names to avoid


    • single character names except for counters or iterators
    • dashes (-) in any package/module name
    • __double_leading_and_trailing_underscore__ names (reserved by Python)

...