Hasty Briefsbeta

LoC Is a Dumb Metric for Functions

a day ago
  • #clean-code
  • #software-development
  • #refactoring
  • Amateur developers often break functions into smaller ones based solely on line count without deeper reasoning.
  • Aesthetic arguments like 'this function doesn’t look clean' are insufficient for refactoring; deeper reasoning is needed.
  • Lines of Code (LoC) is a poor metric for function cleanliness; Cognitive Complexity (CC) is a better alternative.
  • Function decomposition has costs, including reduced locality, linearity, and increased context overhead.
  • Reusability and deduplication should be primary reasons for decomposition, not arbitrary line counts.
  • Testability and dependency injection are valid reasons for extraction, but should be a last resort.
  • Sometimes the calling function itself is doing too much and needs refactoring rather than decomposition.
  • Self-containment, good naming, and comments can improve readability without unnecessary decomposition.
  • Polymorphism should be introduced only when justified, not prematurely for simple cases.
  • Judgment and reasoning should guide refactoring, not arbitrary rules or line counts.