Code quality - alexanderteplov/computer-science GitHub Wiki
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.
- 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).
- 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.
- Halstead complexity measures. These measures:
- Program vocabulary
- Program length
- Calculated program length
- Volume
- Difficulty
- Effort
An example is demonstrated in the picture. We can assure performance, linters, validations of tools like Sonar Cube and other things here.
- Use a coding standard.
- Analyze code — before code reviews (linters).
- Follow code review best practices.
- Refactor legacy code (when necessary).