Post

Coding Convention

Coding Convention

Coding Convention


Prerequites

1
Data Type

What is Coding Convention

1. What is Coding Convention?

Coding Convention is kind of appointment of team about code variable name. We sometimes see the unacceptable name of code or confuse us owing to name.

It depends on company, team and peers and so on. There no general rule for code convention. But The best of convention is if someone who see code at the first time know the flow of code, it is very important and critial part of convention.

But I want to show my convention and why is it good convention for someone who do with our projects.

2. The standard of coding convention

1
<type-prefix><VariableName>

When we distinguish the data type, count of bit and so on. The main point is when we understand the code flow without data type.

Rule 1. How many bite it has.

Rule 2. What the type is difference of another types.

Rule 3. Multi consequence type is using like that

3. List of Coding Convention

3-1. Integer Types

TypePrefixExample
signed chari8i8Value
shorti16i16Index
inti32i32Count
long longi64i64Total
unsigned charu8u8Mask
unsigned shortu16u16Size
unsigned intu32u32Flags
unsigned long longu64u64Timestamp

3-2. Character Types

TypePrefixExample
wchar_twcwcName

3-3. Platform Dependent Types

1
2
3
4
5
6
7
8
9
#ifdef _WIN64
    typedef unsigned __int64 size_t;
    typedef __int64          ptrdiff_t;
    typedef __int64          intptr_t;
#else
    typedef unsigned int     size_t;
    typedef int              ptrdiff_t;
    typedef int              intptr_t;
#endif
TypePrefixExample
size_tssLength
ptrdiff_tpdfpdfOffset
intptr_tiptriptrAddress

3-4. User Defined Types

TypePrefixExample
classccImageProcessor
structssPoint2D
enumeeState
template typettValue

3-5. String Types

TypePrefixExample
stringstrstrPath

3-6. Pointer Types

TypePrefixExample
pointerppData
double pointerp2p2Buffer
triple pointerp3p3Matrix
function pointerfpfpCallback

3-7. Iteration Types

TypePrefixExample
iteratoriteriterNode

3-8. Container Types

TypePrefixExample
arrayarrarrValues
vectorvctvctPoints
vector< vector>vct2vct2Grid

3-9. Multi-Dimensional Arrays

TypePrefixExample
int[ ][ ]arrI32arrI32Image
int**[ ][ ]arrP2I32arrP2I32Tensor

3-10. Concurrency Types

TypePrefixExample
threadththWorker
mutexmtxmtxLock

3-11. Function Types

TypePrefixExample
lambda functionlmdlmdFilter

3-12. File Types

TypePrefixExample
FILE*fpfpLog

3-13. Data / Math Types

TypePrefixExample
nodenodenodeRoot
tensortstsFeature
matrixmatmatTransform

4. Rules of Coding Convention

if, while, for

Braces {} may be omitted when the body of an statement consists of a single line.

1
2
if(bTrue)
    i32Cnt = 10;

global variables : g_ member variables : m_

This post is licensed under CC BY 4.0 by the author.