1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
Coding standards
================
In the header files, #pragma once should be the first line of code.
Then, the order of the inclusions should be, for example, for a MsXpertSuite software (adapt according to different needs):
/////////////////////// stdlib includes
/////////////////////// Qt includes
/////////////////////// pappsomspp includes
/////////////////////// libXpertMass includes
/////////////////////// libXpertMassGui includes
/////////////////////// Local includes
CLASS METHODS
=============
When setting/retrieving member data, use the get/set paradigm.
Do not use the get/set paradigm for any function that performs a computation not
setting/getting a member datum. Note that the get/set function name needs to be
formed using the exact member datum name with the "mxx_" prefix.
When setting/retrieving boolean member data use setXxxx() and isXxxx().
In the get/set function pair, declare/define first the set and then the get.
Functions are always declared/defined in camelCase.
Use std::size_t instead of unsigned int (or uint) when the standard library uses
std::site_t. For Qt containers, the qsizetype type should be used.
Attentions, std:size_t is unsigned, while qsizetype is signed.
Think about it when creating the variable!
VARIABLE / FUNCTION NAMING LOGIC
================================
For class members:
------------------
* Ordinary members: m_peakWidth (camelCase)
* For pointers:
mp_integrationParams (raw pointer)
msp_integrationParams (shared pointer, std::make_shared<T>())
mcsp_integrationParams (shared pointer to const, std::make_shared<const T>())
mpa_integrationParams (a for allocated that indicates the object will require explicit destruction using free())
For variables in function scope: snake_case
-------------------------------------------
The snake-casing operation involves replacing the uppercase character by _<lowercase>.
The mp_, msp_ and mcsp_ prefixes become suffixes:
Example for argumuments to a function:
void
ClassName::exampleFunction(int the_integer, MzIntegrationParamsCSPtr *mz_integration_params_csp)
In general, the variable name snake-cases the class name of the parameter, as shown above.
Avoid using variable names so short that one cannot understand what that variable is about:
int i = 0;
If that is an iteration counter, use 'iter' ('jter', 'kter', for nested loops).
void
exampleFunction(int the_integer, const QString &the_string)
{
qsizetype item_list_count = 0;
}
The parameters and inner-function-scope variables are always snake_case:
* Ordinary variables :
bool should_abort_run = false;
* Pointers:
mz_integration_params_p (raw pointer)
mz_integration_params_sp (shared pointer)
mz_integration_params_csp (shared pointer to const)
Variables in function scope
===========================
A good discipline is to snake-case the class name:
QualifiedMassSpectrum qualified_mass_spectrum;
typedef std::shared_ptr<MassSpectrum> MassSpectrumSPtr;
typedef std::shared_ptr<const MassSpectrum> MassSpectrumCstSPtr;
ENUMS
=====
In general, use class enums:
enum class CapType
{
NONE = 0 << 1,
LEFT = 1 << 1,
RIGHT = 2 << 1,
BOTH = (LEFT | RIGHT)
};
Q_ENUM_NS(CapType)
// Overload bitwise AND operator
inline CapType
operator&(CapType lhs, CapType rhs)
{
return static_cast<CapType>(
static_cast<std::underlying_type_t<CapType>>(lhs) &
static_cast<std::underlying_type_t<CapType>>(rhs));
}
Use a map to provide text strings mapping the enum's values.
In header file:
extern DECLSPEC std::map<Enums::CapType, QString> capTypeMap;
In cpp file:
std::map<Enums::CapType, QString> capTypeMap{{CapType::NONE, "NONE"},
{CapType::LEFT, "LEFT"},
{CapType::RIGHT, "RIGHT"},
{CapType::BOTH, "BOTH"}};
TYPEDEFS
========
typedef std::shared_ptr<MassSpectrum> MassSpectrumSPtr;
typedef QSharePointer<MassSpectrum> MassSpectrumQSPtr;
typedef std::shared_ptr<const MassSpectrum> MassSpectrumCstSPtr;
typedef QSharePointer<const MassSpectrum> MassSpectrumQCstSPtr;
CONSTRUCTION OF OBJECTS AND INITIALIZATION
==========================================
Construction of objects with initialization must be performed traditionally
(C++98). Only when initializing a container, the braces ({xxx,xxx})
initialization is authorized.
CONTAINERS
==========
Use the right container! If the class is going to be a Q_OBJECT that might be used in
scripting, use Qt containers, otherwise use STL containers:
QVector vs std::vector
----------------------
In Qt, recently the QList has an implementation that is like QVector and these
two classes have become almost interchangeable. The Qt guys recommend using QList.
|