mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Update CodingStyle.md: placement of *, & and && declarators
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
c7f0e65b12
commit
d3dc698bba
1 changed files with 58 additions and 58 deletions
|
@ -20,7 +20,6 @@ other editors that implement this coding style, please add them here.
|
|||
continuation lines that are aligned with tabs and then spaces
|
||||
|
||||
* all keywords followed by a '(' have a space in between
|
||||
|
||||
```
|
||||
if (condition)
|
||||
|
||||
|
@ -28,7 +27,6 @@ other editors that implement this coding style, please add them here.
|
|||
```
|
||||
|
||||
* function calls do NOT have a space between their name and argument
|
||||
|
||||
```
|
||||
i = some_function(argument);
|
||||
```
|
||||
|
@ -41,7 +39,6 @@ other editors that implement this coding style, please add them here.
|
|||
|
||||
* all other opening curly braces follow at the end of the line, with a
|
||||
space separating them:
|
||||
|
||||
```
|
||||
if (condition) {
|
||||
dosomething();
|
||||
|
@ -50,7 +47,6 @@ other editors that implement this coding style, please add them here.
|
|||
```
|
||||
|
||||
* both sides of an if / else clause either use or do not use curly braces:
|
||||
|
||||
```
|
||||
if (condition)
|
||||
i = 4;
|
||||
|
@ -66,13 +62,11 @@ other editors that implement this coding style, please add them here.
|
|||
```
|
||||
|
||||
* use space to make visual separation easier
|
||||
|
||||
```
|
||||
a = b + 3 + e / 4;
|
||||
```
|
||||
|
||||
* continuation lines have the operator / comma at the end
|
||||
|
||||
```
|
||||
if (very_long_condition_1 ||
|
||||
condition_2)
|
||||
|
@ -83,7 +77,6 @@ other editors that implement this coding style, please add them here.
|
|||
|
||||
* in a C++ constructor initialization list, the colon is on the same line and
|
||||
continuation lines are aligned as the rule above:
|
||||
|
||||
```
|
||||
ClassName::ClassName() : x(1),
|
||||
y(2),
|
||||
|
@ -93,14 +86,11 @@ other editors that implement this coding style, please add them here.
|
|||
```
|
||||
|
||||
* unfortunate inconsistency
|
||||
* C code usually uses underscores to structure names
|
||||
|
||||
- C code usually uses underscores to structure names
|
||||
```
|
||||
variable_in_C
|
||||
```
|
||||
|
||||
* C++ code usually uses camelCase
|
||||
|
||||
- In contrast, C++ code usually uses camelCase
|
||||
```
|
||||
variableInCPlusPlus
|
||||
```
|
||||
|
@ -110,7 +100,6 @@ other editors that implement this coding style, please add them here.
|
|||
|
||||
* switch statements with blocks are a little bit special (to avoid indenting
|
||||
too far)
|
||||
|
||||
```
|
||||
switch (foo) {
|
||||
case FIRST:
|
||||
|
@ -130,7 +119,22 @@ other editors that implement this coding style, please add them here.
|
|||
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.
|
||||
crazy. Notably, in C++ the lifetime of a variable often coincides with the
|
||||
lifetime of a resource (e.g. file) and therefore the variable is defined
|
||||
at the place where the resource is needed.
|
||||
|
||||
* The `*`, `&` and `&&` declarators are grouped with the name, not the type
|
||||
(classical C-style) as in `char *string` instead of `char* string`. This
|
||||
reflects the precedence rules of the language: `int &i` means that the name
|
||||
`i` stands for a reference [to an object with type `int`], not that
|
||||
`i` stands for an object of the type [reference to `int`].
|
||||
Although this may seem like hairsplitting (both interpretations
|
||||
have the same effect) it is crucial in the
|
||||
definition of multiple variables, such
|
||||
as
|
||||
```
|
||||
struct dive *next, **pprev;
|
||||
```
|
||||
|
||||
* In C++ code, we generally use explicit types in variable declarations for clarity.
|
||||
Use `auto` sparingly and only in cases where code readability improves.
|
||||
|
@ -157,12 +161,11 @@ other editors that implement this coding style, please add them here.
|
|||
spelling and terminology.
|
||||
User-visible strings should be passed to the tr() function to enable
|
||||
translation into other languages.
|
||||
|
||||
* like this
|
||||
- like this
|
||||
```
|
||||
QString msgTitle = tr("Submit user survey.");
|
||||
```
|
||||
* rather than
|
||||
- rather than
|
||||
```
|
||||
QString msgTitle = "Submit user survey.";
|
||||
```
|
||||
|
@ -170,7 +173,7 @@ other editors that implement this coding style, please add them here.
|
|||
This works by default in classes (indirectly) derived from QObject. Each
|
||||
string to be translated is associated with a context, which corresponds
|
||||
to the class name. Classes that are not derived from QObject can generate
|
||||
the tr() functions by using the Q_DECLARE_FUNCTIONS macro:
|
||||
the tr() functions by using the `Q_DECLARE_FUNCTIONS` macro:
|
||||
```
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
@ -202,7 +205,7 @@ other editors that implement this coding style, please add them here.
|
|||
when the particular translation string is encountered for the first time.
|
||||
It remains valid during the whole application's life time.
|
||||
|
||||
Outside of function context, the QT_TRANSLATE_NOOP macro can be used as in
|
||||
Outside of function context, the `QT_TRANSLATE_NOOP` macro can be used as in
|
||||
```
|
||||
struct ws_info_t ws_info[100] = {
|
||||
{ QT_TRANSLATE_NOOP("gettextFromC", "integrated"), 0 },
|
||||
|
@ -214,7 +217,7 @@ struct ws_info_t ws_info[100] = {
|
|||
```
|
||||
Note that here, the texts will be scheduled for translation with the "gettextFromC"
|
||||
context, but the array is only initialized with the original text. The actual
|
||||
translation has to be performed later in code. For C-code, the QT_TRANSLATE_NOOP
|
||||
translation has to be performed later in code. For C-code, the `QT_TRANSLATE_NOOP`
|
||||
macro is defined in the "core/gettext.h" header.
|
||||
|
||||
* UI text style
|
||||
|
@ -236,11 +239,9 @@ struct ws_info_t ws_info[100] = {
|
|||
|
||||
|
||||
* string manipulation
|
||||
|
||||
* user interface
|
||||
In UI part of the code use of QString methods is preferred, see this pretty
|
||||
good guide in [QString documentation][1]
|
||||
|
||||
* core components
|
||||
In the core part of the code, C-string should be used.
|
||||
C-string manipulation is not always straightforward specifically when
|
||||
|
@ -248,7 +249,6 @@ struct ws_info_t ws_info[100] = {
|
|||
to help with this. Documentation and usage examples can be found in
|
||||
[core/membuffer.h][2]
|
||||
|
||||
|
||||
## Sample Settings
|
||||
|
||||
### Emacs
|
||||
|
|
Loading…
Add table
Reference in a new issue