Improving code quality and maintaining consistency across the application components is a crucial aspect of software development.
Static code analyzer
Scan your code to identify potential bugs, bad coding style, security vulnerabilities, Code-smell and to ensure that the code adheres to industry standards and coding conventions.
SonarQube is a popular static code analysis tool that brings default rulesets of industry guidelines. Enterprise specific rules can be defined for each tech stack. For example: Cognitive Complexity < 15 and Cyclomatic Complexity < 10 are ideal target metrics according to industry standards. That means your code has high readability (smaller functions, well structured) and less complexity (less number of decision logic).
Ref: https://docs.sonarqube.org/latest/analyzing-source-code/overview/
Test-Driven-Development
Write and execute automated unit tests for major use cases to catch bugs early. Code coverage up to 80% is good, which means the majority of your code is run by unit tests - either lines, branches or methods. Junit and Nunit are popular frameworks for UT automation.
Ref: https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-nunit
Coding Conventions
Always define naming conventions and coding standards specific to the application technology stack (like Java, .NET, Python etc.) and components (like UI, Service or DB) and emphasize your team to adhere to them throughout the project. It improves readability and speeds up development. It could be a generic industry one or your customer’s own naming conventions and standards.
Ref:
https://www.oracle.com/java/technologies/javase/codeconventions-programmingpractices.html
https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html#:~:text=Class%20names%20should%20be%20nouns,such%20as%20URL%20or%20HTML
https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html#:~:text=Class%20names%20should%20be%20nouns,such%20as%20URL%20or%20HTML
Code Readability
Ensure developers write helpful comments. Inline comments for complex functions and business conditions, a brief comment on top of each file and each class (explaining what it does). Also try using plugins such as Prettier (JS), Csharpier (C#) for better formating. Adequate comments and well-formating improve the readability and faster the development time.
https://stackoverflow.blog/2021/12/23/best-practices-for-writing-code-comments/
Peer review and Lead review
Define a manual code review process where each developer reviews a teammate’s code. Additionally, conduct a lead or a senior engineer review before pushing the code to a shared repository. This manual review process helps to catch bugs, improve code readability and ensure that code aligns with coding standards and best practices defined.
https://www.perforce.com/blog/qac/9-best-practices-for-code-review
Application Security Static Analyzer
Discover security vulnerabilities and reduce risk across all the components. Integrate the IDE with a security static analyzer if application security is a top priority e.g. Checkmark SAST is a popular enterprise-grade tool to identify security vulnerabilities in any code.
https://info.checkmarx.com/hubfs/Why%20Checkmarx-Executive%20Brief%20for%20Partners-V4-010322-UTM-Link%20(1).pdf
Quality Gates
Set code quality goals with quality gates as part of the CI & CD process. It prevents committing a broken code to source control and making builds if the code does not meet a set of conditions. Also, ensure every team member raises a pull request with reviewer approval, no bulk check-in and no check-in allowed without PR approval.
https://docs.sonarqube.org/9.8/user-guide/quality-gates/
https://medium.com/@tarunprakash/quality-gates-a-must-have-thing-for-the-code-analysis-process-75b33d6b49dc
Dependency Checker
Review regularly what libraries are used in your project. Over the development, engineers tend to use open-source libraries to aid their development (e.g. caching, code-formatting, code generator etc.) without knowing the risks attached to it. Enable dependency checker to actively scan through a project’s dependencies to detect and report on publicly disclosed vulnerabilities, thereby improving application security.
Ref:
Summary
The list is not extensive but an essential one to reduce software bugs and improve code quality. This should be a sprint 0 to-do list of every solution architect or technical lead. Determining which applies to the project requirements and consistently following a defined process throughout the project life cycle is the first step to success! Engineering best practices such as using version control, adopting Continuous Integration and so are next steps to be followed.
#engineeringbestpractices #codequality #sdlc

Comments