-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add STYLE.md #573
Add STYLE.md #573
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #573 +/- ##
==========================================
- Coverage 81.23% 81.21% -0.02%
==========================================
Files 192 192
Lines 27061 27061
Branches 4980 4984 +4
==========================================
- Hits 21982 21978 -4
- Misses 3436 3490 +54
+ Partials 1643 1593 -50 ☔ View full report in Codecov by Sentry. |
manually by authors and maintainers, or broken when necessary for practical or | ||
aesthetic reasons. | ||
|
||
## Guidelines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your opinion regarding adding the following statements to the coding style:
if-s
andwhile-s
must have no side effects:
example:
if (q_empty(q)) ... // OK
while(pop(q)) ... // not OK
- Introduce more verbose differences between NULL, 0, false in the code adding explicit conditions:
if (p == NULL) /* for pointers */
if (!b) /* for booleans */
while (in_flight == 0) /* for integers*/
-
Use inline functions instead of macros whenever it's possible.
-
Also, can we eventually move to return code conventions from kernel, where 0 is success, negative error code for a failure, positive values for non failures (ex: bytes read)
-
All macros are written such a way it's possible to use without putting additional parentheses over their parameters.
-
Use PRE()/POST()/assert() to document assumptions in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Agreed.
- We use explicit comparisons to
NULL
and 0 in the current code, so let's stick with that. - Agreed, obviously there's a lot of macro stuff in the current codebase but let's try to limit that going forward.
- This is tough because basically all our functions use positive return codes to signal errors right now. We definitely need some kind of reform here because (similar to the allocator situation) our functions are split between using raft return codes, SQLite codes, dqlite codes, and I think libuv codes in a few cases. But I'm not sure what our stated policy should be in this document.
- Agreed.
- Sure!
Okay, going to experiment with automated reformatting/rewriting now... |
Signed-off-by: Cole Miller <[email protected]>
Signed-off-by: Cole Miller <[email protected]>
Signed-off-by: Cole Miller <[email protected]>
Signed-off-by: Cole Miller <[email protected]>
Let's use this PR to arrive at a consensus about what style new dqlite code should follow. Once that consensus is reached, I'll add more commits updating
.clang-format
and.clang-tidy
and reformatting existing code as needed.Signed-off-by: Cole Miller [email protected]