Implementing Code Quality Practices

1. Implementing Code Reviews

PracticeDetail
Small PRs< 400 lines preferred
ChecklistTests, security, perf, docs
Two reviewersFor sensitive changes
Author tests own codeReviewer verifies tests
ToneSuggest, don't command

2. Implementing Static Analysis

ToolDetects
SpotBugsBug patterns
PMDCode smells, style
CheckstyleFormat conventions
SonarQubeAggregated quality + security
Error ProneCompile-time bug catching

3. Implementing Code Coverage

TargetReasonable Range
Domain logic≥ 80%
Controllers / glue50-70%
Total70-80% pragmatic
ToolJaCoCo
Warning: 100% coverage doesn't mean correct — focus on assertions, not lines hit.

4. Implementing Linting Rules

StackTool
JavaCheckstyle, Spotless
Formatgoogle-java-format, Spotless
Pre-commitReject unformatted code
CI gateFail PR on violation

5. Implementing Documentation Standards

WhatWhere
Public APIsJavadoc; @param, @return, @throws
ArchitectureADRs (Architecture Decision Records)
OnboardingREADME + run book
Don't documentObvious code; rename instead

6. Implementing Code Formatting

Example: Spotless config (Gradle)

spotless {
  java {
    googleJavaFormat("1.22.0")
    removeUnusedImports()
    importOrder("java", "javax", "org", "com", "")
    trimTrailingWhitespace()
    endWithNewline()
  }
}

7. Implementing Code Complexity Limits

MetricThreshold
Cyclomatic complexity≤ 10 per method
Method length≤ 30-50 lines
Class length≤ 300-500 lines
Param count≤ 5 (use object)
Cognitive complexitySonarQube ≤ 15

8. Implementing Refactoring Patterns

PatternUse
Extract MethodBreak long methods
Extract ClassSplit large class by responsibility
Replace Conditional with PolymorphismEliminate type switches
Introduce Parameter ObjectGroup related params
Strangler FigReplace legacy gradually

9. Implementing Technical Debt Tracking

PracticeDetail
// TODO with ticketLink to issue
Debt boardVisible backlog
Budget~ 20% of capacity
SonarQubeTracks debt ratio over time

10. Implementing Best Practices

PrincipleDetail
DRYDon't repeat yourself
KISSKeep it simple
YAGNIYou ain't gonna need it
Boy Scout ruleLeave cleaner than found
Fail fastSurface errors early

11. Implementing Code Smells Detection

SmellFix
Long methodExtract method
God classExtract class
Feature envyMove method to data's class
Primitive obsessionValue object
Switch on typePolymorphism / sealed
Shotgun surgeryConsolidate change point

12. Implementing Code Metrics

MetricSignal
LOCSize proxy (weak)
Cyclomatic / cognitiveComplexity
Coupling (CBO)Inter-class dependencies
Cohesion (LCOM)How focused a class is
DuplicationsSonarQube duplication %
Code churnHot spots = bug-prone