summaryrefslogtreecommitdiffstats
path: root/CodingStyle.md
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-07-03 22:25:44 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-07-04 04:59:15 +0800
commitf5659439ba44b33e802104e488880c0146d8a82d (patch)
tree3f125f354def20290cd692374f57aaf381fb2086 /CodingStyle.md
parent9421429cc66214fc9afd27f64ce6adc4e254f010 (diff)
downloadsubsurface-f5659439ba44b33e802104e488880c0146d8a82d.tar.gz
Codingstyle: add comment on "auto".
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'CodingStyle.md')
-rw-r--r--CodingStyle.md22
1 files changed, 21 insertions, 1 deletions
diff --git a/CodingStyle.md b/CodingStyle.md
index c68f662f1..89c680e4f 100644
--- a/CodingStyle.md
+++ b/CodingStyle.md
@@ -127,11 +127,31 @@ other editors that implement this coding style, please add them here.
## Coding conventions
* variable declarations
- in C code we really like them to be at the beginning of a code block,
+ In C code we really like them to be at the beginning of a code block,
not interspersed in the middle.
in C++ we are a bit less strict about this - but still, try not to go
crazy.
+* In C++ code, we generally use explicit types in variable declarations for clarity.
+ Use `auto` sparingly and only in cases where code readability improves.
+ Two classical examples are:
+ - Iterators, whose type names often are verbose:
+ ```
+ auto = m_trackers.find(when);
+ ```
+ is not only distinctly shorter than
+ ```
+ QMap<qint64, gpsTracker>::iterator it = m_trackers.find(when);
+ ```
+ it will also continue working if a different data structure is chosen.
+ - If the type is given in the same line anyway. Thus,
+ ```
+ auto service = qobject_cast<QLowEnergyService*>(sender());
+ ```
+ is easier to read than and conveys the same information as
+ ```
+ QLowEnergyService* service = qobject_cast<QLowEnergyService*>(sender());
+ ```
* text strings
The default language of subsurface is US English so please use US English
spelling and terminology.