Replies: 11 comments 6 replies
-
Reverse Christmas list/pyramid: Variables should be declared with the longer lines on top: int my_int_with_initialization = 5;
struct my_struct_t my_struct;
float my_float;
int my_int; TBD: Should |
Beta Was this translation helpful? Give feedback.
-
Declarations at top of scope: Variables shall always be declared at top of scope OK: int my_int;
float my_float;
my_int = 0;
if (my_int) {
int another_int = 5;
...
} Not OK: float my_float;
my_float = 0;
int my_int = 5;
if (my_int) {
int another_int = 5;
...
} TBD: int another_int = 5;
int my_int;
float my_float;
my_int = 0;
if (my_int) {
/* another_int only used in this scope */
...
} Also TBD: int my_int;
float my_float;
my_int = 0;
#if FOO
int another_int = 5;
#endif /* FOO */ |
Beta Was this translation helpful? Give feedback.
-
Empty lines after lines containing only OK: if (val) {
/* FOO */
}
return val; Not OK: if (val) {
/* FOO */
}
return val; TBD: switch (val_1) {
case 1:
break;
case 2:
switch (val_2) {
case 1:
break;
default:
break;
}
break;
default:
break;
} |
Beta Was this translation helpful? Give feedback.
-
Alphabetically ordered declarations: float my_float;
int my_int;
int my_int_with_initialization = 5;
struct my_struct_t my_struct; |
Beta Was this translation helpful? Give feedback.
-
Explicit OK (void)memset(val, 0, size);
p = memset(val, 0, size); NOT OK memset(val, 0, size); |
Beta Was this translation helpful? Give feedback.
-
Unsigned values shall be suffixed with OK: uint8_t my_val = 6U;
uint64_t my_long_val = 123ULL;
int8_t my_int = 5;
if (my_val == 6U) { ... } Not OK: uint8_t my_val = 6;
uint64_t my_long_val = 123;
if (my_val == 6) { ... } |
Beta Was this translation helpful? Give feedback.
-
No space between value retrievel and check OK: err = some_func();
if (err) {
return err;
} Not OK: err = some_func();
if (err) {
return err;
} |
Beta Was this translation helpful? Give feedback.
-
Naming scheme of public/internal/static functions For the sake of argument, I'll use the Public function int bt_conn_yyyy(); Internal function int bt_conn_yyyy() Static function static int conn_yyyy();
// or
static int yyyy(); |
Beta Was this translation helpful? Give feedback.
-
enums instead of Unless absolutely necessary that we use specific size constant values, Preferred enum {
BT_COMMON_VALUE_1,
BT_COMMON_VALUE_2,
BT_COMMON_VALUE_3,
BT_COMMON_VALUE_4,
} bt_common_value; Not preferred: #define BT_COMMON_VALUE_1 1
#define BT_COMMON_VALUE_2 2
#define BT_COMMON_VALUE_3 3
#define BT_COMMON_VALUE_4 4 The reasoning here is that functions can take |
Beta Was this translation helpful? Give feedback.
-
Size of array after array in parameters The size/length parameter in an array should come after the array in the parameter list. OK: int foo(uint8_t *data, size_t data_len); Not OK int foo(size_t data_len, uint8_t *data); |
Beta Was this translation helpful? Give feedback.
-
Locking due to inactivity |
Beta Was this translation helpful? Give feedback.
-
As per the Discord thread (https://discord.com/channels/720317445772017664/916269984529907772/916270130726572072) this RFC will try to gather information about which code style we want to follow in the Bluetooth Subsystem. We will only define the style for the Bluetooth subsystem at this point, as trying to make these guidelines/rules tree wide will take much longer time, and the different subsystem already have different style.
The goal is to create a set of code style that we can officially refer to when reviewing pull requests, as currently many reviewers have their own personal opinion where some are conflicting, making it hard for contributors to add code.
Each rule/guideline will be in their own comment, which will allow us to "vote" which rules we want the most (let's cross fingers for that to actually work, otherwise we may need to do this in a different way).
Things to consider for this:
Beta Was this translation helpful? Give feedback.
All reactions