Summary
Split large header files (result.h at 913 lines, error_info related headers) into smaller, focused modules to improve compilation times, maintainability, and code navigation.
5W1H Specification
- Who: common_system maintainers
- What: Decompose large monolithic headers into logical sub-headers
- Where:
include/kcenon/common/patterns/ and include/kcenon/common/types/
- When: Before v0.3.0.0 (recommended for next major refactoring cycle)
- Why:
result.h is 913 lines - exceeds recommended 500 lines per header
- Compile time increases with header size due to template instantiation
- Code navigation and understanding is harder in large files
- Difficult to identify which components are needed by consumers
- How: Extract logical units into separate headers with a master umbrella header
Priority
MEDIUM - Does not block functionality but impacts developer experience and build performance.
Current State Analysis
result.h (913 lines)
| Component |
Lines |
Proposed File |
| error_info struct |
~50 |
result/error_info.h |
| Result core |
~200 |
result/result_core.h |
| Result monadic ops |
~150 |
result/result_ops.h |
| Result helpers |
~100 |
result/result_helpers.h |
| Macros |
~50 |
result/result_macros.h |
| VoidResult typedef |
~20 |
result/void_result.h |
| std::formatter specialization |
~40 |
result/result_format.h |
| try_catch utilities |
~100 |
result/exception_conversion.h |
| error_category extensions |
~80 |
result/error_category.h |
| Documentation/examples |
~120 |
Inline in each file |
Proposed Directory Structure
include/kcenon/common/patterns/
├── result.h # Umbrella header (backward compatible)
└── result/
├── fwd.h # Forward declarations
├── error_info.h # error_info struct and error codes
├── error_category.h # Error category extensions
├── result_core.h # Result<T> class definition
├── result_ops.h # map(), and_then(), or_else()
├── result_helpers.h # make_result(), make_error()
├── result_macros.h # COMMON_RETURN_IF_ERROR, etc.
├── void_result.h # VoidResult typedef
├── result_format.h # std::formatter specialization
└── exception_conversion.h # try_catch, try_catch_void
Backward Compatibility Strategy
Phase 1: Split with Umbrella (Non-breaking)
// result.h - becomes umbrella header
#pragma once
#include "result/fwd.h"
#include "result/error_info.h"
#include "result/error_category.h"
#include "result/result_core.h"
#include "result/result_ops.h"
#include "result/result_helpers.h"
#include "result/result_macros.h"
#include "result/void_result.h"
#include "result/result_format.h"
#include "result/exception_conversion.h"
// Backward compatibility: all includes work via umbrella
Phase 2: Selective Import (Optional optimization)
// Consumer can choose fine-grained includes for faster builds
#include <kcenon/common/patterns/result/result_core.h>
#include <kcenon/common/patterns/result/result_ops.h>
// Skip formatting and macros if not needed
Tasks
Phase 1: Header Split (Priority)
Phase 2: Testing
Phase 3: Documentation
Acceptance Criteria
Performance Targets
| Metric |
Current |
Target |
| result.h line count |
913 |
<100 (umbrella only) |
| Largest sub-header |
N/A |
<300 lines |
| Full include compile |
baseline |
no regression |
| Minimal include compile |
N/A |
30% faster |
Downstream Impact
| Repository |
Impact |
| thread_system |
None (uses umbrella header) |
| container_system |
None (uses umbrella header) |
| logger_system |
None (uses umbrella header) |
| network_system |
Optional: can use fine-grained includes |
| messaging_system |
Optional: can use fine-grained includes |
Risk Mitigation
- Breaking changes: Umbrella header ensures full backward compatibility
- Include order: Use include guards and forward declarations
- Circular deps: Design with clear dependency direction (fwd → core → ops → helpers)
Related Issues
- container_system: Similar refactoring needed for
container.h (910 lines)
- Cross-system: Part of unified_system code quality improvement initiative
Summary
Split large header files (
result.hat 913 lines,error_inforelated headers) into smaller, focused modules to improve compilation times, maintainability, and code navigation.5W1H Specification
include/kcenon/common/patterns/andinclude/kcenon/common/types/result.his 913 lines - exceeds recommended 500 lines per headerPriority
MEDIUM - Does not block functionality but impacts developer experience and build performance.
Current State Analysis
result.h (913 lines)
result/error_info.hresult/result_core.hresult/result_ops.hresult/result_helpers.hresult/result_macros.hresult/void_result.hresult/result_format.hresult/exception_conversion.hresult/error_category.hProposed Directory Structure
Backward Compatibility Strategy
Phase 1: Split with Umbrella (Non-breaking)
Phase 2: Selective Import (Optional optimization)
Tasks
Phase 1: Header Split (Priority)
result/subdirectory structureerror_info.hwith error_info struct and error codeserror_category.hwith error category extensionsresult_core.hwith Result class definitionresult_ops.hwith monadic operations (map, and_then, or_else)result_helpers.hwith factory functionsresult_macros.hwith helper macrosvoid_result.hwith VoidResult typedefresult_format.hwith std::formatter specializationexception_conversion.hwith try_catch utilitiesfwd.hwith forward declarationsresult.hto be umbrella headerPhase 2: Testing
Phase 3: Documentation
Acceptance Criteria
#include <kcenon/common/patterns/result.h>works unchangedPerformance Targets
Downstream Impact
Risk Mitigation
Related Issues
container.h(910 lines)