Coding-style doc updated

This commit is contained in:
Éder F. Zulian
2018-04-11 19:55:14 +02:00
parent 2fc774eece
commit 73c95f8f8f

View File

@@ -32,46 +32,120 @@ password if required.
## DRAMSys Coding Style for C++ Code ## DRAMSys Coding Style for C++ Code
+ Indentation #### Indentation
4 spaces are used for indentation.
+ Breaking long lines and strings #### Breaking long lines and strings
Coding style is all about readability and maintainability using commonly
Coding style is all about readability and maintainability using commonly available tools.
available tools.
The limit on the length of lines is 80 columns and this is a strongly The limit on the length of lines is 80 columns and this is a strongly
preferred limit. preferred limit.
Statements longer than 80 columns will be broken into sensible chunks, Statements longer than 80 columns will be broken into sensible chunks, unless
unless exceeding 80 columns significantly increases readability and does not exceeding 80 columns significantly increases readability and does not hide
hide information. Descendants are always substantially shorter than the information. Descendants are always substantially shorter than the parent and
parent and are placed substantially to the right. The same applies to are placed substantially to the right. The same applies to function headers
function headers with a long argument list. However, never break with a long argument list. However, never break user-visible strings such as
user-visible strings such as printed messages, because that breaks the printed messages, because that breaks the ability to grep for them.
ability to grep for them.
+ Placing Braces and Spaces #### Declaring variables
Declare each variable on a separate line.
+ Naming Avoid short or meaningless names (e.g., "a", "b", "aux").
+ Functions Wait when declaring a variable until it is needed.
```c++
// Wrong
int a, b;
char *c, *d;
// Correct
int height;
int width;
char *nameOfThis;
short counter;
char itemDelimiter = ' ';
```
Classes always start with an upper-case letter (e.g, MemoryManager,
TracePlayer, PythonCaller, etc.), being **DRAMSys** a notable exception to the
rule.
Acronyms are camel-cased (e.g., TlmRecorder, not TLMRecorder, Dram, not DRAM).
#### Whitespace
Always use a single space after a keyword and before a curly brace:
```c++
// Wrong
if(foo){
}
// Correct
if (foo) {
}
```
For pointers or references, always use a single space between the type and
'\*' or '&', but no space between the '\*' or '&' and the variable name:
```c++
char *x;
const QString &myString;
const char * const y = "hello";
```
Surround binary operators with spaces.
No space after a cast.
Avoid C-style casts when possible.
```c++
// Wrong
char* blockOfMemory = (char* ) malloc(data.size());
// Correct
char *blockOfMemory = reinterpret_cast<char *>(malloc(data.size()));
```
Do not put multiple statements on one line.
Use a new line for the body of a control flow statement:
```
// Wrong
if (foo) bar();
// Correct
if (foo)
bar();
```
## DRAMSys Coding Style for Python Code ## DRAMSys Coding Style for Python Code
+ We follow the PEP8 style guide. We follow the PEP8 style guide.
+ How to use vim plugins **Hint:**
There is a plugin for VIM. More information can be found in
[vim.org](https://www.vim.org/scripts/script.php?script_id=2914).
## Using Astyle in Qt Creator ## Using Astyle in Qt Creator
+ Select **Help** > **About Plugins** > **C++** > **Beautifier** to enable the plugin. + Select **Help** > **About Plugins** > **C++** > **Beautifier** to enable the
plugin.
+ Restart Qt Creator to be able to use the plugin (close Qt Creator and open it again). + Restart Qt Creator to be able to use the plugin (close Qt Creator and open
it again).
+ Select **Tools** > **Options** > **Beautifier** to specify settings for beautifying files. + Select **Tools** > **Options** > **Beautifier** to specify settings for
beautifying files.
+ Select the **Enable auto format on file save** check box to automatically beautify files when you save them. + Select the **Enable auto format on file save** check box to automatically
beautify files when you save them.
## References ## References