Code quality - alexanderteplov/computer-science GitHub Wiki

Code quality

Measurement

Here are five of the key traits to measure for higher quality.

  • Reliability. It relates to the number of defects and availability of the software. The number of defects can be measured by running a static analysis tool. Software availability can be measured using the mean time between failures (MTBF).
  • Maintainability. You can’t use a single metric to ensure maintainability. Some metrics you may consider to improve maintainability are the number of stylistic warnings and Halstead complexity measures.
  • Testability. Testability can be measured based on how many test cases you need to find potential faults in the system. The size and complexity of the software can impact testability.
  • Portability. Portability measures how usable the same software is in different environments. It relates to platform independence. There isn’t a specific measure of portability.
  • Reusability. Reusability can be measured by the number of interdependencies. Running a static analyzer can help you identify these interdependencies.

Metrics

Defect Metrics

  • Identification of the stage in which the defect originates.
  • Number of open defect reports.
  • Time to identify and correct defects.
  • Defect density (e.g., number of defects per lines of code).

Complexity Metrics

  1. Cyclomatic complexity (CYC) is a software metric used to determine the complexity of a program. It is a count of the number of decisions in the source code. The higher the count, the more complex the code.
  2. Halstead complexity measures. These measures:
    • Program vocabulary
    • Program length
    • Calculated program length
    • Volume
    • Difficulty
    • Effort

Code quality gates

An example is demonstrated in the picture. We can assure performance, linters, validations of tools like Sonar Cube and other things here.

The way to improve code quality

  1. Use a coding standard.
  2. Analyze code — before code reviews (linters).
  3. Follow code review best practices.
  4. Refactor legacy code (when necessary).

Links

⚠️ **GitHub.com Fallback** ⚠️