Repository navigation
Remove LCOM (Lack of Cohesion of Methods) metric from the core engine - #1042
Merged
Merged
Conversation
The existing lcom_score computed total_flux / total_args across a class's methods -- a ratio of unrelated regex hit-counts with no connection to actual method-to-method cohesion (#1018). Investigating a proper redesign (regex-extracting self./this./$this-> instance-variable sets per method, then comparing set overlap across methods) surfaced two prerequisite bugs: the class-boundary regex doesn't handle nested classes (#1040), and two of the four function-slicing modes silently drop nested/inner functions (#1041). Both would corrupt any per-class or per-method metric, not just LCOM. Even with those fixed, a regex-only cohesion measure has no reliable way to see through common idioms that make it wrong in predictable, language- specific directions: shared "blob" attributes (self.state/self.config/ self.logger) make god-objects look maximally cohesive; Python's @Property splits one logical field into two names, making genuinely cohesive classes look fragmented; composition/delegation hides real coupling that never touches self directly. That's a systematic style-driven bias, not noise -- worse than the metric being merely imprecise. At best it would be a within-class trend signal, not the bounded 0-100 authoritative score the field currently implies. Given that, removing it outright rather than reimplementing it under those constraints -- consistent with the recent metrics epic (#1025) trimming metrics an AST-less engine can't structurally back. state_entanglement (density of state mutations, a different and simpler signal) is untouched. Removes lcom_score from detector.py's ClassInfo/class-physics calculation and record_keeper.py's class_data table + insert. No other consumer existed (grepped gitgalaxy/recorders, gitgalaxy/metrics, and the golden master fixtures before removing). Verified with crucible_check.py (zero diff against the golden-master corpus) and audit_check.py (ruff baseline regenerated, all pure line-shifts). Closes #1018. Co-Authored-By: Claude Sonnet 5 <[email protected]>
3 tasks
Contributor
6 of 7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lcom_score, which computedtotal_flux / total_args— a ratio of unrelated regex hit-counts with no real connection to method-to-method cohesion (Redesign LCOM (Lack of Cohesion of Methods) calculation using AST-less regex sets #1018).self.state/self.config/self.logger) make god-objects look maximally cohesive; Python's@propertyidiom splits one logical field into two names, making genuinely cohesive classes look fragmented; composition/delegation hides real coupling that never touchesselfdirectly. At best this makes it a within-class trend signal, not the bounded 0-100 authoritative score the field currently implies — so removing it outright rather than reimplementing it under those constraints, consistent with the recent metrics epic (Epic: Remove overreaching AST-less heuristic metrics (post-db_complexity wave) #1025) trimming metrics an AST-less engine can't structurally back.state_entanglement(density of state mutations — a different, simpler signal) is untouched.Test plan
python -m pytest tests/core_engine/test_detector.py tests/tools_recorders/test_record_keeper.py -q— 84 passedpython tests/tools/crucible_check.py— zero diff against the golden-master corpus (full_precision + zero_dependency)python tests/tools/audit_check.py --regenerate— ruff baseline regenerated (all pure line-shifts), mypy/dead-key cleangalaxyscoperun againstgitgalaxy/corewith--db-only, confirmedclass_dataschema and insert both work post-removalgitgalaxy/recorders,gitgalaxy/metrics, and both golden-master fixtures for otherlcom_scoreconsumers before removing — none foundCloses #1018.
🤖 Generated with Claude Code