Skip to content

Remove LCOM (Lack of Cohesion of Methods) metric from the core engine - #1042

Merged
squid-protocol merged 1 commit into
mainfrom
fix/1018-remove-lcom-metric
Aug 4, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/1018-remove-lcom-metric

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • Removes lcom_score, which computed total_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).
  • Investigating a proper regex-based redesign (per-method instance-variable set extraction + overlap comparison) surfaced two prerequisite bugs that would corrupt any per-class/per-method metric: nested classes truncate the outer class's scope (bug(core): Nested class boundaries truncate outer class scope #1040), and nested/inner functions are silently dropped by two of the four function-slicing modes (bug(core): Nested functions are silently dropped from extraction #1041).
  • Even with those fixed, a regex-only cohesion measure has systematic, style-driven blind spots rather than merely being imprecise: shared "blob" attributes (self.state/self.config/self.logger) make god-objects look maximally cohesive; Python's @property idiom splits one logical field into two names, making genuinely cohesive classes look fragmented; composition/delegation hides real coupling that never touches self directly. 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 passed
  • python 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 clean
  • Manual galaxyscope run against gitgalaxy/core with --db-only, confirmed class_data schema and insert both work post-removal
  • Grepped gitgalaxy/recorders, gitgalaxy/metrics, and both golden-master fixtures for other lcom_score consumers before removing — none found

Closes #1018.

🤖 Generated with Claude Code

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]>
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit d2673a2 into main Aug 4, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the fix/1018-remove-lcom-metric branch August 4, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redesign LCOM (Lack of Cohesion of Methods) calculation using AST-less regex sets

1 participant