-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Problem
The codebase currently has three different layers for database access, creating inconsistency and confusion. This incomplete transition needs to be resolved by standardizing on a single approach.
Current State - Three Access Patterns
Method 1: Direct SQLite (files_shl.cc)
// Direct database calls - low levelMethod 2: Sql Class Wrapper
Sql db;
auto star1 = db.getstar(snum); // Member function approach
auto planet1 = db.getplanet(s, p); // Inconsistent with free functionsMethod 3: Free Functions (Most Common)
auto star2 = ::getstar(snum); // Global scope
auto star3 = getstar(snum); // Most widely usedCurrent Usage Analysis
- Free functions (
getstar(),getplanet(), etc.) are used throughout most of the codebase - Sql class methods (
Sql::getstar()) are used inconsistently in some files - This creates confusion about which pattern to use
Recommended Standardization
Standardize on free functions as they are:
- Most widely adopted in the codebase
- Simplest to use (no object instantiation required)
- Consistent with the command pattern architecture
- Already integrated with the module system
Files Requiring Updates (~10 files)
Need to audit and identify files using:
// Replace this pattern:
Sql db;
auto star = db.getstar(snum);
// With this pattern:
auto star = getstar(snum);Implementation Steps
- Audit Phase: Identify all locations using
Sql::getstar(),Sql::getplanet(), etc. - Replace Phase: Convert to free function calls
- Cleanup Phase: Remove unused Sql class methods if no longer needed
- Documentation Phase: Update any documentation to reflect standard pattern
Benefits
- Single, consistent database access pattern
- Reduced cognitive overhead for developers
- Simpler API surface
- Better integration with existing command architecture
- Easier testing and mocking
Success Criteria
- All database access uses free functions (
getstar(),getplanet(), etc.) - No remaining usage of
Sql::get*()member functions - Consistent pattern across all command files
- Build succeeds without warnings
- Game functionality remains unchanged
- Documentation updated to reflect standard pattern
Priority
Medium - Improves code consistency and developer experience, part of broader modernization.
Related Issues
- Replace direct stars[] array access with getstar()/putstar() pattern #18 Replace direct stars[] array access with getstar()/putstar() pattern
- Global state dependency reduction
Reactions are currently unavailable