Skip to content
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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

Add STYLE.md #573

wants to merge 4 commits into from

Conversation

cole-miller
Copy link
Contributor

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 cole.miller@canonical.com

Copy link

codecov bot commented Feb 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.21%. Comparing base (e814a1c) to head (e60adcd).
Report is 19 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

manually by authors and maintainers, or broken when necessary for practical or
aesthetic reasons.

## Guidelines
Copy link
Contributor

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:

  1. if-s and while-s must have no side effects:
    example:
if (q_empty(q)) ... // OK

while(pop(q)) ... // not OK
  1. 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*/
  1. Use inline functions instead of macros whenever it's possible.

  2. 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)

  3. All macros are written such a way it's possible to use without putting additional parentheses over their parameters.

  4. Use PRE()/POST()/assert() to document assumptions in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Agreed.
  2. We use explicit comparisons to NULL and 0 in the current code, so let's stick with that.
  3. Agreed, obviously there's a lot of macro stuff in the current codebase but let's try to limit that going forward.
  4. 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.
  5. Agreed.
  6. Sure!

@cole-miller
Copy link
Contributor Author

Okay, going to experiment with automated reformatting/rewriting now...

Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Signed-off-by: Cole Miller <cole.miller@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants