User Tools

Site Tools


coding_style

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
coding_style [2016/03/10 12:28] – [Examples] jmgrcoding_style [2023/04/25 16:52] (current) – external edit 127.0.0.1
Line 26: Line 26:
 | member variable | m_someExample | | | member variable | m_someExample | |
 | global variables | gSomeExample | should be avoided | | global variables | gSomeExample | should be avoided |
-| function | someExample() | |+| function | someExample() | function names should begin with a verb: computeMap(), displayWindow() |
 | member function | someExample() | | | member function | someExample() | |
 | getter function | name() | not getName(), Qt convention | | getter function | name() | not getName(), Qt convention |
Line 33: Line 33:
 | template parameter | SomeExample | | | template parameter | SomeExample | |
  
-Never use abbreviations in names, having long names is not an issue: all IDEs have an auto-completion feature.+**Never use abbreviations in names, having long names is not an issue: all IDEs have an auto-completion feature.**
 <code cpp> <code cpp>
 // Bad // Bad
Line 48: Line 48:
     //...     //...
 } }
 +</code>
 +
 +**Prefer using meaningful names instead of "one letter" names like i,j,k.**
 +<code cpp>
 +// Bad
 +for(int i = 0; i < ducks.size(); ++i)
 +{
 +    //...
 +}
 +
 +// Good
 +for(int duckIndex = 0; duckIndex < ducks.size(); ++duckIndex)
 +{
 +    //...
 +}
 +</code>
 +
 +**Variables representing GUI elements should be suffixed by their type**
 +<code cpp>
 +// Bad
 +QPushButton *exitApplication;
 +QLabel *duckCount;
 +
 +// Good
 +QPushButton *exitApplicationPushButton;
 +QLabel *duckCountLabel;
 </code> </code>
 ===== Code files ===== ===== Code files =====
Line 53: Line 79:
 ==== Code separation ==== ==== Code separation ====
  
-Generally speaking, each class/struct should have its declaration in one file (header) and its definition in another file (source file). If a class/struct is very small then it can be contained in a header, for example if it only contains variables and no functions. Qt specific: note that QObject/QWidget-based classes have to have their own header file in order to the MOC (Qt'meta compiler) to find them. +Generally speaking, each class/struct should have its declaration in one file (header) and its definition in another file (source file). If a class/struct is very small then it can be contained in a header, for example if it only contains variables and no functions. Qt specific: note that QObject/QWidget-based classes have to have their own header file in order to the [[http://doc.qt.io/qt-5/moc.html|moc]] (Qt'Meta-Object Compiler) to find them.
 ==== Naming ==== ==== Naming ====
  
coding_style.1457612919.txt.gz · Last modified: 2023/04/25 16:52 (external edit)