-
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
Conversation
Finish the draft of coding style
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.
I draft a coding style, and I have some question.
contrib/CODINGSTYLE.md
Outdated
3. The QT-related function name uses Camel case, | ||
whereas non-QT-related function name uses snake case. | ||
4. The name of the class member starts with ```m_```. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
According to @tigercosmos and my suggestion,
here is the brief and rough conclusion.
However, it seems that the naming of the macros is inconsistent.
Is there any naming rule about macros?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use MM_DECL*
.
contrib/CODINGSTYLE.md
Outdated
### Formatting | ||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||
2. There exists a space between the definition of the classes/functions. | ||
3. A long line should be devided to several shorter lines. | ||
|
||
### Class | ||
1. The class should follow [the rule of five](https://en.cppreference.com/w/cpp/language/rule_of_three). | ||
|
||
### 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 comment
The 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 comment
The 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 comment
The 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.
@yungyuc If you are availabe, may you start a review? |
contrib/CODINGSTYLE.md
Outdated
* [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 comment
The reason will be displayed to describe this comment to others. Learn more.
R3DWidget
is not a good example. QT related and non-QT can be different.
Also, let's clarify if we want HTTPRequest
or HttpReuqest
.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
R3DWidget
is not a good example. QT related and non-QT can be different. Also, let's clarify if we wantHTTPRequest
orHttpReuqest
.
Sorry, I don't get it.
How does the cpp program call the HTTPRequest
or HttpReuqest
function?
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.
R3DWidget
is not a good example. QT related and non-QT can be different. Also, let's clarify if we wantHTTPRequest
orHttpReuqest
.
By the way, do you mean that if the class use HTTPRequest
or HttpReuqest
,
the class belongs to a QT-related classes?
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.
R*
classes are Qt classes in modmesh. I name them with the leading R
because it's the next letter of Q
. I do not want to give them the leading letter Q
which is already used by Qt itself.
R3DWidget
is a modmesh-made Qt derived class. The CamelCase rule is ambiguous for it because "3D" is an acronym for "three-dimensional" but "3" cannot be capitalized. Both R3DWidget
and R3dWidget
are CamelCased.
@tigercosmos used HTTPRequest
and HttpRequest
to explain that you need to consider how to deal with acronyms. The former keeps each of the letter in the acronym "HTTP" in upper-case. The latter treats the whole acronym as a word, and makes it "Http".
Treating an acronym as a word will make naming more consistent. So for acronyms, let's go with HttpRequest
.
contrib/CODINGSTYLE.md
Outdated
1. The class names use Camel case, such as ```class R3DWidget;```. | ||
2. The name of the variable / using-declarations uses snake case, | ||
such as ```R3DWidget * viewer;``` and ```using size_type = std::size_t;```. | ||
3. The QT-related function name uses Camel case, |
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 the difference with point 1.
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.
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 comment
The 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 comment
The 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.
What is the style of the helper class?
Should I mention the helper class in this manual?
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.
It's complicated
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.
It's complicated
Ok, we may skip the helper class temporaily.
contrib/CODINGSTYLE.md
Outdated
such as ```R3DWidget * viewer;``` and ```using size_type = std::size_t;```. | ||
3. The QT-related function name uses Camel case, | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
4. The name of the class member starts with ```m_```. | |
4. The name of the class member starts with `m_`. |
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 is the difference between ` and ```?
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.
` is for inline code, ``` is for code block
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.
contrib/CODINGSTYLE.md
Outdated
whereas non-QT-related function name uses snake case. | ||
4. The name of the class member starts with ```m_```. | ||
5. The name of [macros](https://en.cppreference.com/w/cpp/preprocessor/replace) starts with ```DECL_MM_```. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
6. The [using-declarations](https://en.cppreference.com/w/cpp/language/using_declaration) ends with ```_type```. | |
6. The [using-declarations](https://en.cppreference.com/w/cpp/language/using_declaration) ends with `_type`. |
contrib/CODINGSTYLE.md
Outdated
### Formatting | ||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||
2. There exists a space between the definition of the classes/functions. | ||
3. A long line should be devided to several shorter lines. |
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 the recommended length? 120?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
note that for python code, the length limit is 80 for sure.
@ThreeMonth03 you should mention the issue number when you raise the PR. |
This PR references #350 |
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.
- Rename the file to
/CODINGSTYLE.md
- Remove
Introduction
- Distinguish non-Qt and Qt code
- Review all indentation, blank lines, and markdown formatting
- Remove recursion words
contrib/CODINGSTYLE.md
Outdated
@@ -0,0 +1,43 @@ | |||
# Coding Style | |||
## Introduction |
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.
I don't think we need this section whose only content is the table of contents.
contrib/CODINGSTYLE.md
Outdated
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 directory contrib/
is for code not for how to write code.
contrib/CODINGSTYLE.md
Outdated
* [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 comment
The 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.
contrib/CODINGSTYLE.md
Outdated
### Naming | ||
1. The class names use Camel case, such as ```class R3DWidget;```. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Please use perfect indentation of markdown. And "```" is rst, not markdown.
contrib/CODINGSTYLE.md
Outdated
3. The QT-related function name uses Camel case, | ||
whereas non-QT-related function name uses snake case. | ||
4. The name of the class member starts with ```m_```. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use MM_DECL*
.
contrib/CODINGSTYLE.md
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
is enforced by CI already. I don't think we need to write it down in the style guide.
contrib/CODINGSTYLE.md
Outdated
|
||
### Formatting | ||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean a blank line by "space"?
contrib/CODINGSTYLE.md
Outdated
### Formatting | ||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||
2. There exists a space between the definition of the classes/functions. | ||
3. A long line should be devided to several shorter lines. |
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.
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?
contrib/CODINGSTYLE.md
Outdated
3. A long line should be devided to several shorter lines. | ||
|
||
### 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 comment
The 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 = default
and = delete
as much as possible?
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.
yes, that's what I meant.
contrib/CODINGSTYLE.md
Outdated
### Formatting | ||
1. It is necessary to obey the [clang-format](https://clang.llvm.org/docs/index.html), or you must fail the github action. | ||
2. There exists a space between the definition of the classes/functions. | ||
3. A long line should be devided to several shorter lines. | ||
|
||
### Class | ||
1. The class should follow [the rule of five](https://en.cppreference.com/w/cpp/language/rule_of_three). | ||
|
||
### 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 comment
The 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.
- Rename the file to /CODINGSTYLE.md
- Remove Introduction
- Distinguish non-Qt and Qt code
- Review all indentation, blank lines, and markdown formatting
- Remove recursion words
# Coding Style | ||
|
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.
I remove the introduction, and modify the filename to CODINGSTYLE.md.
1. Class names use CamelCase, for example: `class CallProfiler;`. | ||
- Qt-related classes prepend an additional `R`, like `class RLine;`. | ||
* A class is considered Qt-related if its parent class belongs to the Qt library. | ||
|
||
2. Variable names and using-declarations use snake_case: | ||
- Example variable: `R3DWidget * viewer;` | ||
- Example using-declaration: `using size_type = std::size_t;` | ||
|
||
3. Qt-related function names use CamelCase, while non-Qt-related function names use snake_case. | ||
- Functions are Qt-related if they belong to a Qt-related class. | ||
- Example Qt-related function: `QMdiSubWindow * RManager::addSubWindow(Args &&... args);` | ||
- Example non-Qt-related function: `void initialize_buffer(pybind11::module & mod);` |
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.
I distinquish and define the Qt-related classes and functions in the list.
Additionally, I reformat the file.
7. Acronyms within names should be treated as words instead of using ALL_CAPS_CONSTANTS. | ||
- Example classes: `class HttpRequest;` | ||
- Example function: `void update_geometry_impl(StaticMesh const & mh, Qt3DCore::QGeometry * geom);` |
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.
Here is the naming rule about acronyms.
|
||
## Class | ||
|
||
1. It's advisable to explicitly define constructors and destructors for classes whenever possible. |
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.
According to the discussion, I modify the rule of five.
@yungyuc I finish the modification of the document, but I'm not sure whether it could be code review. |
Thanks, @ThreeMonth03 . The CI failure might be #365 , for which I just merged the fix @tigercosmos made in #367 . Could you please rebase to rerun the CI once the merged code has CI passed? |
Sync and fix the bug in CICD.
@yungyuc |
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.
- For Qt just say Qt. No need to be "-related".
- When it's type alias, say type alias. Do not mistake with using-declaration.
- Wording to distinguish C++ and Python.
- More accurate title is "Constructors", not "Class".
## Naming | ||
|
||
1. Class names use CamelCase, for example: `class CallProfiler;`. | ||
- Qt-related classes prepend an additional `R`, like `class RLine;`. |
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.
Just say "Qt classes". It is redundant to write "-related".
- Qt-related classes prepend an additional `R`, like `class RLine;`. | ||
* A class is considered Qt-related if its parent class belongs to the Qt library. | ||
|
||
2. Variable names and using-declarations use snake_case: |
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.
It is incorrect to say using-declarations. The use case you mentioned is type aliasing: https://en.cppreference.com/w/cpp/language/type_alias . Please correct.
- Example Qt-related function: `QMdiSubWindow * RManager::addSubWindow(Args &&... args);` | ||
- Example non-Qt-related function: `void initialize_buffer(pybind11::module & mod);` | ||
|
||
4. Class members begin with `m_`. |
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.
Only C++
|
||
5. [Macros](https://en.cppreference.com/w/cpp/preprocessor/replace) start with `MM_DECL_`. | ||
|
||
6. [Using-declarations](https://en.cppreference.com/w/cpp/language/using_declaration) end with `_type`. |
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.
I think you mistake with https://en.cppreference.com/w/cpp/language/type_alias .
}; /* end of modmesh */ | ||
``` | ||
|
||
3. It is highly recommended to include references in comment blocks. |
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.
Just say it is recommended.
- For C++, no specific line length limit is set. | ||
- For Python, adhere to an 80-character limit per line. | ||
|
||
## Class |
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.
It's more accurate to use "Constructors" as the subject.
@ThreeMonth03 why closed? |
@ThreeMonth03 please make complete and explicit arguments before closing the PR. |
@yungyuc @tigercosmos |
@ThreeMonth03 You confuse people by referring to the private discussions between you and me. Please make an argument instead of delegating the reasoning to information that is not made public. |
@yungyuc I feel terribly sorry for my imprecise argument. @tigercosmos |
@ThreeMonth03 it's okay to keep the PR open until you can continue, but it's also okay to reopen it when you are available. |
I add the draft about the coding-style.
There are some detail need to discuss.