-
Notifications
You must be signed in to change notification settings - Fork 43
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
Write the coding-style guide for Modmesh #362
Changes from 2 commits
4ebd550
0595df0
cfc0736
4fc0850
6326549
5cca9ac
9177d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,43 @@ | ||||||
# Coding Style | ||||||
## Introduction | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this section whose only content is the table of contents. |
||||||
This is the coding style guide for Modmesh. | ||||||
* [Introduction](#introduction) | ||||||
* [Naming](#naming) | ||||||
* [Comments](#comments) | ||||||
* [Formatting](#formatting) | ||||||
* [Class](#class) | ||||||
* [Functions](#functions) | ||||||
|
||||||
### Naming | ||||||
1. The class names use Camel case, such as ```class R3DWidget;```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. Please distinguish Qt and non-Qt classes. If not mentioned, the style refers to non-Qt classes, and you should take non-Qt classes for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't get it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
By the way, do you mean that if the class use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@tigercosmos used Treating an acronym as a word will make naming more consistent. So for acronyms, let's go with |
||||||
2. The name of the variable / using-declarations uses snake case, | ||||||
such as ```R3DWidget * viewer;``` and ```using size_type = std::size_t;```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use perfect indentation of markdown. And "```" is rst, not markdown. |
||||||
3. The QT-related function name uses Camel case, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference with point 1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I notice that whether the class is related QT, the naming of the class is Camel case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class names are mostly CamelCase, although exceptions are not rare when it comes to a helper class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What is the style of the helper class? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's complicated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok, we may skip the helper class temporaily. |
||||||
whereas non-QT-related function name uses snake case. | ||||||
4. The name of the class member starts with ```m_```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between ` and ```? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ` is for inline code, ``` is for code block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
5. The name of [macros](https://en.cppreference.com/w/cpp/preprocessor/replace) starts with ```DECL_MM_```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to @tigercosmos and my suggestion, However, it seems that the naming of the macros is inconsistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting, @yungyuc could you decide a prefix name and let's change all the other? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use |
||||||
6. The [using-declarations](https://en.cppreference.com/w/cpp/language/using_declaration) ends with ```_type```. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
### Comments | ||||||
1. The comment blocks follow the [doxygen styles](https://www.doxygen.nl/manual/docblocks.html). | ||||||
2. The one-line comment, ```/* end of NamespaceOrClassName */```, | ||||||
should be appended to the end of a namespace or class. | ||||||
For example : | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a blank line between section, paragraph, and literal blocks. |
||||||
```c++ | ||||||
namespace modmesh | ||||||
{ | ||||||
// More code... | ||||||
}; /* end of modmesh */ | ||||||
``` | ||||||
3. It is highly recommended to add the reference in the comment block. | ||||||
|
||||||
### Formatting | ||||||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
2. There exists a space between the definition of the classes/functions. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean a blank line by "space"? |
||||||
3. A long line should be devided to several shorter lines. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the recommended length? 120? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we have not been able to decide what is a proper length. @ThreeMonth03 , could you please make it explicit that we do not yet have a set limitation on line width? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note that for python code, the length limit is 80 for sure. |
||||||
|
||||||
### Class | ||||||
1. The class should follow [the rule of five](https://en.cppreference.com/w/cpp/language/rule_of_three). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The rule of five is not exactly a coding style. Or do you mean to explicit write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's what I meant. |
||||||
|
||||||
### Functions | ||||||
1. The recursive function should be replaced with the iterative function, unless it is inevitable to be used. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I add more concrete example or basic suggestion(like const member function/ copy by const reference) for the items? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know we have such a rule. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not look like a coding style. It is a performance (HPC) concern. It should not be included in this file. |
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.
Please rename to
/CODINGSTYLE.md
. The directorycontrib/
is for code not for how to write code.