In: Electrical Engineering
List down three ways of determination of good code.
The quality of the code is important, as it impacts the overall software quality. And quality impacts how safe, secure, and reliable your code base is.
High quality is critical for many development teams today. And it's especially important for those developing safety-critical systems.
Good code is high quality. And it’s clean code. It stands the test of time. Bad code is low quality. It won’t last long.
Essentially, code that is considered good:
Testing Isn’t Enough
Programmers aren’t perfect. Manual code reviews and testing will never find every error in the code.
A study on “Software Defect Origins and Removal Methods” found that individual programmers are less than 50% efficient at finding bugs in their own software. And most forms of testing are only 35% efficient. This makes it difficult to determine quality.
Coding Errors Lead to Risk
The quality of code in programming is important. When code is low quality, it might introduce safety or security risks. If software fails — due to a security violation or safety flaw — the results can be catastrophic or fatal.
Quality Is Everyone’s Responsibility
Quality is everyone’s job. The developer. The tester. The manager. High quality should be the goal throughout the development process.
Reliability
Reliability measures the probability that a system will run without failure over a specific period of operation. It relates to the number of defects and availability of the software.
Number of defects can be measured by running a static analysis tool. Software availability can be measured using the mean time between failures (MTBF). Low defect counts are especially important for developing a reliable code base.
Maintainability
Maintainability measures how easily software can be maintained. It relates to the size, consistency, structure, and complexity of the code base. And ensuring maintainable source code relies on a number of factors, such as testability and understandability.
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. Both automation and human reviewers are essential for developing maintainable codebases.
Testability
Testability measures how well the software supports testing efforts. It relies on how well you can control, observe, isolate, and automate testing, among other factors.
Testability can be measured based on how many test cases you need to find potential faults in the system. Size and complexity of the software can impact testability. So, applying methods at the code level — such as cyclomatic complexity — can help you improve the testability of the component.
Portability
Portability measures how usable the same software is in different environments. It relates to platform in dependency.
There isn’t a specific measure of portability. But there are several ways you can ensure portable code. It’s important to regularly test code on different platforms, rather than waiting until the end of development. It’s also a good idea to set your compiler warning levels as high as possible — and use at least two compilers. Enforcing a coding standard also helps with portability.
Reusability
Reusability measures whether existing assets — such as code — can be used again. Assets are more easily reused if they have characteristics such as modularity or loose coupling.
Reusability can be measured by the number of inter dependencies. Running a static analyzer can help you identify these inter dependencies