1---2name: code-review3description: Code review checklist for the HPCC Platform. Use when reviewing C++ code changes, examining components for issues, or checking best practices. Covers memory management, thread safety, style compliance, security, API compatibility, and correctness.4---56# HPCC Platform Code Review Guidelines78## Review Philosophy9- The goal is to catch bugs, design problems, security issues, and readability concerns.10- Consider interactions between components, e.g. Dali, Thor, and Roxie components.1112## Critical Quality Checks & Checklist1314### 1. Memory Management15- **Owned<> vs Linked<>**: `Owned<X>` takes ownership of a new/returned pointer; `Linked<X>` shares ownership. Verify proper use.16- Check for memory/resource leaks in general. Are exceptions properly handled so resources are released?17- **queryFoo()** returns are NOT linked — caller must `Link()` if retaining beyond guaranteed lifetime.18- **getFoo()** returns ARE linked — assign to `Owned<>` or return directly.19- Are `CInterface`-derived objects properly release-counted?2021### 2. Thread Safety22- Look for race conditions, proper locking, and synchronization issues, especially in server components.23- Are shared variables protected by critical sections or atomics? Watch for TOCTOU (time-of-check-time-of-use).24- Check for potential deadlocks (lock ordering).25- Are `CriticalBlock`, `ReadLockBlock`, `WriteLockBlock` scoped correctly?2627### 3. Code Style (Essential Rules)28- Adherence to coding standards in `devdoc/StyleGuide.md`.29- **Braces**: Allman style — `{` and `}` on their own line. Single-line blocks may omit braces unless nested.30- **Naming**: `CamelCase` for classes, `camelCase` for variables/functions/methods.31- **No trailing whitespace**.32- Prefer `constexpr` over macros. Avoid default parameters (use method overloading instead).33- Format specifiers: `%u` for unsigned, `%d` for signed.3435### 4. Error Handling & Correctness36- Consistent error reporting and logging throughout the codebase.37- Edge cases: empty inputs, null pointers, integer overflow, off-by-one.38- Are exceptions caught at the right level? Do they properly release resources?3940### 5. Security & API Compatibility41- Validate input sanitization, authentication, and authorization mechanisms.42- Ensure changes don't break existing client interfaces or backward compatibility.43- Are public interface changes minimized and documented?44- SQL/command injection vectors?4546### 6. Efficiency47- Consider effects on query execution and distributed data throughput.48- Unnecessary copies of large objects?49- String operations in hot paths (prefer `StringBuffer` over repeated `std::string` concatenation)?5051### 7. Component-Specific Concerns52- **Dali**: Distributed metadata — watch for consistency, replication, and transaction issues.53- **Thor**: Batch processing — watch for data partitioning, memory limits, and spill-to-disk handling.54- **Roxie**: Real-time queries — watch for latency, caching, and query lifecycle management.55- **ESP**: Web services — watch for authentication, input validation, and CORS/CSRF.56- **ECL compiler**: Language changes — verify backward compatibility with existing ECL code.5758## Review Questions to Consider59- Are there any efficiency concerns or performance bottlenecks?60- Is the code thread-safe and properly synchronized?61- Could the code be refactored to improve maintainability and reuse?62- Are there any memory or resource leaks?63- Does this change maintain backward compatibility?64- Are error conditions properly handled and logged?65- Is the change properly tested with appropriate test coverage?