# Code Style Guide This project follows a **Modified Allman** brace and formatting style. It prioritizes **visual clarity, symmetry, and logical separation of blocks** over strict line compactness. --- ## Overview ### Key Principles - Indentation with **tabs** (width = 4). - **Opening braces `{`** always start on a new line. - **`} else {`** and **`} catch {`** appear on the same line for compact flow. - **Spaces inside parentheses only when non-empty:** - `( arg1, arg2 )` - `main()` - **Classes and structs:** PascalCase - **Variables, objects, and functions:** camelCase - **Constants/macros:** UPPER_CASE_WITH_UNDERSCORES --- ## Examples ### `if / else` structure ```cpp if ( condition ) { doSomething(); } else { doSomethingElse( arg1, arg2 ); } ``` ### `try / catch` structure ```cpp try { runOperation(); } catch ( const std::exception& ex ) { handleError( ex ); } ``` ### Class and method naming ```cpp class DataAnalyzer { public: DataAnalyzer( const std::string& filePath ) : filePath( filePath ) { } void processDataAndGenerateReport() { try { loadDataFromFile( filePath ); analyzeResultsAndPrintSummary(); } catch ( const std::runtime_error& error ) { std::cerr << "Error: " << error.what() << std::endl; } } private: std::string filePath; void loadDataFromFile( const std::string& path ) { if ( path.empty() ) { throw std::runtime_error( "File path cannot be empty." ); } else { std::cout << "Loading data from: " << path << std::endl; } } void analyzeResultsAndPrintSummary() { std::cout << "Analyzing data..." << std::endl; std::cout << "Summary: OK" << std::endl; } }; ``` ### `main()` function ```cpp int main() { DataAnalyzer analyzer( "results.csv" ); try { analyzer.processDataAndGenerateReport(); } catch ( const std::exception& ex ) { std::cerr << "Unhandled exception: " << ex.what() << std::endl; } return 0; } ``` --- ## `.clang-format` configuration Save this file as `.clang-format` in your project root: ```yaml # === Style: Modified Allman (tabs, compact else/catch, and selective parentheses spacing) === # Naming conventions: # · Classes and structs: PascalCase (e.g., MyClass, PlayerController) # · Variables, objects, and functions: camelCase (e.g., myVariable, calculateScore) # · Constants or macros: UPPER_CASE_WITH_UNDERSCORES # · if/else and try/catch share the same brace layout: # if ( condition ) # { # ... # } else { # ... # } # try # { # ... # } catch ( const std::exception& e ) { # ... # } BasedOnStyle: LLVM IndentWidth: 4 UseTab: Always BraceWrapping: AfterClass: true AfterControlStatement: true AfterEnum: true AfterFunction: true AfterNamespace: true AfterStruct: true AfterUnion: true BeforeCatch: false BeforeElse: false IndentBraces: false SplitEmptyFunction: false SplitEmptyRecord: false SplitEmptyNamespace: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: false SpaceBeforeParens: Always SpaceInEmptyParentheses: false SpaceInParens: true SpacesInAngles: false SpacesInCStyleCastParentheses: true SpacesInSquareBrackets: false KeepEmptyLinesAtTheStartOfBlocks: true ColumnLimit: 0 AlignConsecutiveAssignments: true AlignConsecutiveDeclarations: true AlignEscapedNewlines: Left AlignOperands: true AlignTrailingComments: true BreakBeforeBraces: Allman