From 4ebd5502642b3786d485ff2d6904e858dfbfb1d8 Mon Sep 17 00:00:00 2001 From: ThreeMonth03 Date: Mon, 10 Jun 2024 13:39:48 +0800 Subject: [PATCH 1/2] Finish the draft of coding style --- contrib/CODINGSTYLE.md | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 contrib/CODINGSTYLE.md diff --git a/contrib/CODINGSTYLE.md b/contrib/CODINGSTYLE.md new file mode 100644 index 00000000..9fed9e2a --- /dev/null +++ b/contrib/CODINGSTYLE.md @@ -0,0 +1,43 @@ +# Coding Style +## Introduction +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;```. +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, +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```. + +### 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 : +```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. +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. \ No newline at end of file From cfc07362418103fada3fc31ec56da8a99af28da3 Mon Sep 17 00:00:00 2001 From: ThreeMonth03 Date: Mon, 17 Jun 2024 16:24:44 +0800 Subject: [PATCH 2/2] format and enhance the content of the codingstyle.md --- CODINGSTYLE.md | 56 ++++++++++++++++++++++++++++++++++++++++++ contrib/CODINGSTYLE.md | 43 -------------------------------- 2 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 CODINGSTYLE.md delete mode 100644 contrib/CODINGSTYLE.md diff --git a/CODINGSTYLE.md b/CODINGSTYLE.md new file mode 100644 index 00000000..a7a59d65 --- /dev/null +++ b/CODINGSTYLE.md @@ -0,0 +1,56 @@ +# Coding Style + +## Naming + +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);` + +4. Class members begin with `m_`. + +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`. + +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);` + +Certainly! Here's a more coherent version: + +## Comments + +1. Comment blocks should follow [Doxygen style guidelines](https://www.doxygen.nl/manual/docblocks.html). + +2. For one-line comments like `/* end of NamespaceOrClassName */`, + place them at the end of namespaces or classes. + Example usage: + ```c++ + namespace modmesh + { + // More code... + }; /* end of modmesh */ + ``` + +3. It is highly recommended to include references in comment blocks. + +## Formatting + +1. Ensure there is a blank line between the definitions of classes and functions. + +2. Long lines should be divided into shorter ones. + - For C++, no specific line length limit is set. + - For Python, adhere to an 80-character limit per line. + +## Class + +1. It's advisable to explicitly define constructors and destructors for classes whenever possible. \ No newline at end of file diff --git a/contrib/CODINGSTYLE.md b/contrib/CODINGSTYLE.md deleted file mode 100644 index 9fed9e2a..00000000 --- a/contrib/CODINGSTYLE.md +++ /dev/null @@ -1,43 +0,0 @@ -# Coding Style -## Introduction -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;```. -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, -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```. - -### 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 : -```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. -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. \ No newline at end of file