C++
This document outlines the coding standards and best practices for C++ development in our projects.
Naming Conventions
Classes and Structs
Use PascalCase for class and struct names
Names should be descriptive and represent the purpose
Functions and Methods
Use camelCase for function and method names
Function names should be verbs or verb phrases
Variables
Use camelCase for local variables
Use snake_case with prefix
m_for member variablesUse ALL_CAPS for constants
Infinity C++ SDK
Infinity provides a header-only C++ library that allows developers to leverage many of the error handling abstractions that Rust offers. see the Infinity C++ SDK documentation for more details.
Modern C++ Practices
Use Smart Pointers
Prefer smart pointers over raw pointers to manage memory automatically.
Use auto Keyword
Use auto for type deduction when the type is obvious or overly verbose.
Range-Based For Loops
Prefer range-based for loops for iterating over containers.
Error Handling
Use Exceptions
Use exceptions for error handling instead of error codes.
Code Organization
Header Guards
Use #pragma once or include guards in header files.
Include Order
Related header file
C system headers
C++ standard library headers
Other libraries' headers
Your project's headers
Best Practices
Use
constwherever possible - Make functions and variables const when they don't modify stateAvoid global variables - Use namespaces, classes, or singletons instead
Follow RAII - Resource Acquisition Is Initialization
Prefer composition over inheritance
Write self-documenting code - Use clear names instead of excessive comments
Keep functions small - Each function should do one thing well
Documentation
Use Doxygen-style comments for public APIs:
Formatting
Follow the published clang-format style for consistent code formatting across the codebase.
All code must be properly formatted before committing.