Summary
Standardize the Result API by establishing member methods as the primary interface and deprecating free functions. Analysis shows member methods are used 5.6x more frequently than free functions (510 vs 91 usages).
Current State
Dual API Problem
The Result class provides two parallel APIs for the same operations:
Member Method API (Primary - 510 usages)
result.is_ok() // 200 usages
result.value() // 196 usages
result.error() // 114 usages
result.is_err()
result.unwrap()
result.map(func)
result.and_then(func)
Free Function API (Secondary - 91 usages)
is_ok(result) // Part of 91 total
get_value(result)
get_error(result)
is_error(result)
value_or(result, default)
map(result, func)
and_then(result, func)
Usage Analysis
| API Style |
Usage Count |
Percentage |
| Member Methods |
510 |
84.9% |
| Free Functions |
91 |
15.1% |
| Ratio |
5.6:1 |
|
Test File Inconsistency
| Test File |
API Used |
result_test.cpp |
Free Functions only |
improved_result_test.cpp |
Member Methods only |
| Integration tests |
Member Methods (predominant) |
Problem Analysis
| Issue |
Impact |
| Two ways to do the same thing |
API confusion |
| Inconsistent test patterns |
Unclear best practices |
| Documentation shows both |
User uncertainty |
| Cognitive load |
Developers must choose |
Kent Beck Principles
- Reveals Intention: Single clear API is better
- Fewest Elements: One API style, not two
Proposed Solution
Phase 1: Documentation Standardization (Immediate)
Phase 2: Test Consistency (Short-term)
Phase 3: Deprecation (Medium-term)
Phase 4: Removal (Long-term - 2+ major versions)
Migration Guide
Free Function to Member Method Mapping
| Free Function |
Member Method |
is_ok(result) |
result.is_ok() |
is_error(result) |
result.is_err() |
get_value(result) |
result.value() |
get_error(result) |
result.error() |
value_or(result, def) |
result.value_or(def) |
map(result, func) |
result.map(func) |
and_then(result, func) |
result.and_then(func) |
Code Migration Example
// Before (free function style)
if (is_ok(result)) {
auto value = get_value(result);
process(value);
} else {
log_error(get_error(result));
}
// After (member method style)
if (result.is_ok()) {
auto value = result.value();
process(value);
} else {
log_error(result.error());
}
Tasks
Immediate
Short-term
Medium-term
Long-term
Acceptance Criteria
Files to Modify
| File |
Changes |
include/kcenon/common/patterns/result/utilities.h |
Add deprecation attributes |
docs/guides/BEST_PRACTICES.md |
Update API recommendations |
docs/guides/RESULT_MIGRATION_GUIDE.md |
Add free→member migration |
tests/result_test.cpp |
Add comment explaining purpose |
tests/improved_result_test.cpp |
Ensure comprehensive coverage |
Related Issues
Summary
Standardize the Result API by establishing member methods as the primary interface and deprecating free functions. Analysis shows member methods are used 5.6x more frequently than free functions (510 vs 91 usages).
Current State
Dual API Problem
The Result class provides two parallel APIs for the same operations:
Member Method API (Primary - 510 usages)
Free Function API (Secondary - 91 usages)
Usage Analysis
Test File Inconsistency
result_test.cppimproved_result_test.cppProblem Analysis
Kent Beck Principles
Proposed Solution
Phase 1: Documentation Standardization (Immediate)
Phase 2: Test Consistency (Short-term)
result_test.cppas "free function contract tests"improved_result_test.cppcomprehensively covers member APIPhase 3: Deprecation (Medium-term)
[[deprecated]]to free functions inutilities.h:Phase 4: Removal (Long-term - 2+ major versions)
utilities.hto contain only:ok(),make_error()try_catch()COMMON_ASSIGN_OR_RETURNMigration Guide
Free Function to Member Method Mapping
is_ok(result)result.is_ok()is_error(result)result.is_err()get_value(result)result.value()get_error(result)result.error()value_or(result, def)result.value_or(def)map(result, func)result.map(func)and_then(result, func)result.and_then(func)Code Migration Example
Tasks
Immediate
Short-term
Medium-term
[[deprecated]]attributes to free functionsLong-term
Acceptance Criteria
Files to Modify
include/kcenon/common/patterns/result/utilities.hdocs/guides/BEST_PRACTICES.mddocs/guides/RESULT_MIGRATION_GUIDE.mdtests/result_test.cpptests/improved_result_test.cppRelated Issues