Skip to content

Commit e5d3bfc

Browse files
author
Amanda Butler
authored
Merge pull request #1132 from ARMmbed/AnotherButler-patch-5
Add namespace guidelines to style.md
2 parents 3e36bcc + 7dbf5d3 commit e5d3bfc

File tree

1 file changed

+15
-20
lines changed
  • docs/reference/contributing/guidelines

1 file changed

+15
-20
lines changed

docs/reference/contributing/guidelines/style.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,55 +71,35 @@ uint32_t adc_function(analogin_t *obj, uint32_t options)
7171
### Rules
7272
7373
- Indentation - four spaces. Please do not use tabs.
74-
7574
- Braces - K&R style.
76-
7775
- One true brace style (1TBS) - use braces for statements of type `if`, `else`, `while` and `for` (exception [from K&R](http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)).
78-
7976
- One line per statement.
80-
8177
- Preprocessor macro starts at the beginning of a new line; the code inside is indented according to the code above it.
82-
8378
- Cases within `switch` are indented (exception from K&R).
84-
8579
- Space after statements of type `if`, `while`, `for`, `switch`. The same applies to binary operators (like, `+` and `*`) and the ternary operator (`?` and `:`).
86-
8780
- Each line preferably has at most 120 characters.
88-
8981
- Comments should use proper spelling and grammar.
90-
9182
- For pointers or references, the symbols `*` or `&` are adjacent to a name (`analogin_t *obj`. `analogin_t &obj`). If you omit the name, place the space between the type and `*` (such as `int *` or `int &`).
92-
9383
- For function return pointers or references, the symbols `*` or `&` are adjacent to a function name (`int *func()` or `int &func()`).
94-
9584
- Don't leave trailing spaces at the end of lines.
96-
9785
- Empty lines should have no trailing spaces.
98-
9986
- Unix line endings are default option for files.
100-
10187
- Use capital letters for macros.
102-
10388
- A file should have an empty line at the end.
10489
10590
### Naming conventions
10691
10792
#### Classes
10893
10994
- Begin with a capital letter, and each word within a class also begins with a capital letter (AnalogIn, BusInOut).
110-
11195
- Methods contain small letters, with words separated by underscore.
112-
11396
- Private members start with an underscore: ``__User defined types (typedef)))``.
114-
11597
- Structures - `suffix _t` - to denote it is a user-defined type.
116-
11798
- Enumeration - the type name and values name - same naming convention as classes (for example MyNewEnum).
11899
119100
#### Functions
120101
121102
- Contain lower case letters (as methods within classes).
122-
123103
- Words separated by underscore (wait_ms, read_u16).
124104
125105
An example:
@@ -163,6 +143,21 @@ struct analogin_s {
163143
typedef struct analogin_s analogin_t;
164144
```
165145

146+
#### Namespaces
147+
148+
Namespaces used to group subsystems are lower case, such as `rtos` and `event`. If not in a specific subsystem, C++ APIs are in namespace `mbed`. A few APIs remain in the global namespace for backward compatibility.
149+
150+
Occasionally, namespaces are used to act as-if "static singleton" objects. One example is namespace `ThisThread` in `rtos` (which was modeled after C++11 `std::this_thread`). These namespaces follow the class naming convention, so calls to their functions look like calls to static class methods.
151+
152+
Below is an example of typical namespace use in a source file:
153+
154+
```
155+
using namespace rtos;
156+
157+
ThisThread::sleep_for(1000);
158+
159+
```
160+
166161
### Doxygen documentation
167162

168163
All functions and methods should contain documentation using Doxygen.

0 commit comments

Comments
 (0)