Code Style
Coding conventions and guidelines.
Plugify follows a custom code style designed to ensure consistency, readability, and maintainability across the project. While we don’t adhere to popular style conventions like Google Style or LLVM Style, our style is straightforward and easy to follow. This page outlines the key aspects of our code style and provides instructions for using the provided Clang-Tidy
and Clang-Format
configurations.
Why a Custom Style?
We decided to use a custom code style for Plugify to tailor the formatting and conventions to the specific needs of the project. This allows us to:
- Maintain a consistent look and feel across the codebase.
- Optimize for readability and maintainability.
- Avoid unnecessary complexity introduced by some popular style guides.
Key Aspects of Plugify's Code Style
1. Naming Conventions
- Variables: Use
camelCase
for variable. - Classes, Structs and Functions: Use
PascalCase
for class and struct names. - Constants: Use
UPPER_SNAKE_CASE
for constants.
2. Indentation and Spacing
- Use tabs for indentation (no spaces).
- Place opening braces
{
on the same line as the statement. - Use a single space after keywords like
if
,for
, andwhile
.
3. Line Length
- Limit lines to 120 characters for better readability.
4. Comments
- Use
//
for single-line comments and/* ... */
for multi-line comments. - Place comments above the code they describe, not inline.
5. Header Guards
- Use
#pragma once
for header files to avoid multiple inclusions.
Using Clang-Tidy and Clang-Format
To make it easier to adhere to the code style, we provide Clang-Tidy
and Clang-Format
configuration files in the repository. These tools automatically format your code and enforce style rules.
1. Clang-Format
Clang-Format
automatically formats your code according to the style guidelines. To use it:
- Install
Clang-Format
if you haven’t already. - Run the following command in the root of the repository:
This will format the file in place.
2. Clang-Tidy
Clang-Tidy
performs static analysis and enforces additional style and best practices. To use it:
- Install
Clang-Tidy
if you haven’t already. - Run the following command in the root of the repository:
Automating Formatting
To automate formatting and analysis, you can integrate Clang-Format
and Clang-Tidy
into your IDE or build system. Most modern IDEs (e.g., Visual Studio, CLion, VSCode) support these tools natively.
Why Consistency Matters
Consistent code style is crucial for:
- Readability: Makes the code easier to understand for all contributors.
- Maintainability: Reduces the cognitive load when navigating the codebase.
- Collaboration: Ensures that everyone follows the same conventions, reducing friction during code reviews.
Tips for Contributors
- Run Formatting Tools: Always run
Clang-Format
andClang-Tidy
before submitting a pull request. - Follow the Style Guide: Adhere to the naming conventions, indentation rules, and other guidelines outlined above.
- Ask for Help: If you’re unsure about any aspect of the code style, feel free to ask in the Discord community or open an issue on GitHub.
Conclusion
Plugify’s custom code style is designed to be simple, consistent, and easy to follow. By using the provided Clang-Tidy
and Clang-Format
configurations, you can ensure that your code adheres to the project’s style guidelines. Consistent code style is essential for maintaining a high-quality codebase, and we appreciate your efforts to follow these conventions.