Big-Ugly Style Update (#278)

* Bulk replaced tabs with spaces
* Bulk removed trailing whitespace from lines
* Replaced c-style comments with c++-style comments in file banners
* Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable
* Cleanup ordering and spacing of include directives
* Bulk renaming of header file extensions from '.h' to '.hpp'.
* Update CODING-STYLE.md
* Update target_compile_features from cxx_std_11 to cxx_std_20.
* Refresh .clang-format file.  Still needs a lot of tweaking.
This commit is contained in:
Jaye Evins
2026-01-07 19:43:34 -05:00
committed by GitHub
parent 3cd173a37f
commit 1c902230fe
454 changed files with 51827 additions and 52031 deletions
+39 -20
View File
@@ -4,29 +4,20 @@ Glabels Coding Style
This file describes the coding style used in all glabels source code. Any
patches or pull requests should adhere to this style.
:bulb: **Note:** The top-level glabels source directory includes a *.clang-format* file.
This file can be used with `clang-format` to reformat code to a reasonable approximation
of the style described here.
Formatting
----------
### Tabs vs. Spaces
Tabs are only used at the beginning of a line, and only used to express
indentation level. Spaces are used for any other type of vertical alignment,
e.g. aligning function arguments. This ensures that the code displays
correctly everywhere, regardless of the viewer's tab size, and does not inflict
the viewer with my choice of tab size (8 spaces).
I use the emacs smart-tabs-mode to automatically enforce this. See
https://www.emacswiki.org/emacs/SmartTabs for more information.
Use spaces for all code indentation and line-to-line alignment of code elements.
(e.g. aligning function arguments). This ensures that the code displays
correctly everywhere.
### Indentation Style
Glabels code uses the Allman style (a.k.a "BSD Style") of code indentation.
Glabels code uses the Allman[^1] style (a.k.a "BSD Style") of code indentation.
I.e. the brace associated with a control statement is placed on the next line,
indented to the same level as the control statement. Statements within the
braces are indented to the next level.
@@ -50,8 +41,6 @@ else
Also applies to function, class and namespace declaration statements.
See https://en.wikipedia.org/wiki/Indent_style#Allman_style for more
information.
### Parenthesis
@@ -98,8 +87,8 @@ Code Organization
Generally code is organized into modules. Usually a module defines a single
class or a small namespace of functions/constants/etc. A module is defined by
two files: a header file (its specification) and an implementation file.
Header filenames have a ".h" extension and implementation filenames have a
".cpp" extension.
Header filenames have a `.hpp` extension[^2] and implementation filenames have a
`.cpp` extension.
### Self-contained Headers
@@ -114,8 +103,8 @@ shall include its header file before any other includes.
All header files should have an ifndef guard to prevent multiple inclusion.
```
#ifndef ns_Module_h
#define ns_Module_h
#ifndef ns_Module_hpp
#define ns_Module_hpp
...
@@ -127,7 +116,7 @@ All header files should have an ifndef guard to prevent multiple inclusion.
Header files should be included in the following order.
1. header file for this module (e.g. this would be "Foo.h" in "Foo.cpp").
1. header file for this module (e.g. this would be `Foo.hpp` in `Foo.cpp`).
2. Glabels header files.
3. Qt header files
3. C++ system header files (e.g. STL files)
@@ -152,3 +141,33 @@ include directives instead.
- Private definitions are placed in unnamed namespaces to limit scope to the current translation unit.
- All other glabels code is placed in the top-level "glabels" namespace.
- Nested namespace declarations should follow the more concise C++17 syntax
```
namespace glabels::model
{
...
}
```
Notes
-----
### Emacs
The following is an excerpt from my emacs configuration supporting the style
```
(defun my-c++-hook ()
(setq c-default-style "bsd"
c-basic-offset 8
indent-tabs-mode nil
show-trailing-whitespace t))
(add-hook 'c++-mode-hook 'my-c++-hook)
```
References
----------
[^1]: https://en.wikipedia.org/wiki/Indent_style#Allman_style
[^2]: [C++ Weekly - Ep 442 - Stop Using .h For C++ Header Files!](https://www.youtube.com/watch?v=mr3sOT-Delg)