Decomposed the "God Class" `kdtree_analytics.go` into three distinct files: - `kdtree_analytics.go`: Core tree analytics - `peer_trust.go`: Peer trust scoring logic - `nat_metrics.go`: NAT-related metrics Renamed `ComputeDistanceDistribution` to `ComputeAxisDistributions` for clarity. Created `AUDIT-API.md` to document the findings and changes. Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
1.4 KiB
API Design and Ergonomics Audit
Findings
1. "God Class" in kdtree_analytics.go
The file kdtree_analytics.go exhibited "God Class" characteristics, combining core tree analytics with unrelated responsibilities like peer trust scoring and NAT metrics. This made the code difficult to maintain and understand.
2. Inconsistent Naming
The method ComputeDistanceDistribution in kdtree.go was inconsistently named, as it actually computed axis-based distributions, not distance distributions.
Changes Made
1. Decomposed kdtree_analytics.go
To address the "God Class" issue, I decomposed kdtree_analytics.go into three distinct files:
kdtree_analytics.go: Now contains only the core tree analytics.peer_trust.go: Contains the peer trust scoring logic.nat_metrics.go: Contains the NAT-related metrics.
2. Renamed ComputeDistanceDistribution
I renamed the ComputeDistanceDistribution method to ComputeAxisDistributions to more accurately reflect its functionality.
3. Refactored kdtree.go
I updated kdtree.go to use the new, more focused modules. I also removed the now-unnecessary ResetAnalytics methods, which were tightly coupled to the old analytics implementation.
Conclusion
These changes improve the API's design and ergonomics by making the code more modular, maintainable, and easier to understand.