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.
    int exampleVariable = 42;
    
  • Classes, Structs and Functions: Use PascalCase for class and struct names.
    class ExampleClass {};
    struct ExampleStruct {};
    void ExampleFunction();
    
  • Constants: Use UPPER_SNAKE_CASE for constants.
    const int EXAMPLE_CONSTANT = 100;
    

2. Indentation and Spacing

  • Use tabs for indentation (no spaces).
  • Place opening braces { on the same line as the statement.
    if (condition) {
        // Code here
    }
    
  • Use a single space after keywords like if, for, and while.
    if (condition) {
        // Code here
    }
    

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.
    // This is a single-line comment
    int exampleVariable = 42;
    
    /*
     * This is a multi-line comment
     * describing a block of code.
     */
     void ExampleVariable();
    

5. Header Guards

  • Use #pragma once for header files to avoid multiple inclusions.
    #pragma once
    
    class ExampleClass {};
    

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:

  1. Install Clang-Format if you haven’t already.
  2. Run the following command in the root of the repository:
   clang-format -i path/to/your/file.cpp

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:

  1. Install Clang-Tidy if you haven’t already.
  2. Run the following command in the root of the repository:
   clang-tidy path/to/your/file.cpp

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 and Clang-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.