Skip to main content

What are the Code Quality Best Practices followed for Enterprise Application Development?

Improving code quality and maintaining consistency across the application components is a crucial aspect of software development.

Software Code Quality Best Practices Checklist

In this post let’s look at some of the key engineering best practices to help produce high-quality code.

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:

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.

Ref:
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.

Ref:
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

Popular posts from this blog

Fix: "Cannot set a credential for principal 'sa' . (Microsoft SQL Server, Error: 15535)" and “User is not associated with a trusted sql server connection" Errors

Recently, I had happen to struck with the following errors when I tried to reset the SA password through the SQL Server 2008 R2 Express. " Cannot set a credential for principal 'sa' . (Microsoft SQL Server, Error: 15535) " and then, “ User is not associated with a trusted sql server connection " From my research I have found the solution and that perfectly worked in SQL management studio. Hence, I thought of sharing my findings with others. ========================================================= Advertisement: Choosing .NET Core Worker Services OR Windows Services? ========================================================= Steps to reset the password in SQL Server 2008 R2 Express and fix for the errors: Step 1. Go to SQL Server Instance -> Properties/Security tab and change the mode to SQL Server authentication mode. Step 2. Go to Security/Logins, then open 'sa' login properties,          a. Uncheck the "Enforce passwor...

How to Set Up SonarQube in IntelliJ: A Step-by-Step Guide

SonarQube in IntelliJ: (Looking for SonarLint then check here:  How to install and execute Sonarlint ) Setting up SonarQube in IntelliJ can significantly enhance your code quality by identifying bugs and vulnerabilities. Follow these steps to integrate SonarQube with IntelliJ: Step 1 :  Install SonarLint PluginOpen IntelliJ and navigate to Settings. Go to Plugins > Marketplace. Search for SonarLint, install it, and restart the IDE. Step 2 : Configure SonarLint Click on SonarLint at the bottom left of IntelliJ. Select Configure SonarLint. In the popup, check the box for Bind project to SonarQube/SonarCloud and click on Configure the connection. Step 3 :  Set Up the ConnectionIn the new popup, click the + icon to add a new connection. If the + icon is not visible, go to File > Settings > New UI and disable it. Apply changes and restart the IDE. Name your connection and select SonarQube. Enter the SonarQube URL (e.g., https://sonar.prod.company.com) and click Next....

How to implement JUnit 5 in Your Maven or Gradle Project: A Step-by-Step Guide for Java Testing

Unit Testing JUnit Learn how to integrate JUnit 5 in your Maven or Gradle project for efficient Java testing. This guide covers adding dependencies, creating test classes, writing test methods, and running tests in IntelliJ IDEA and Visual Studio Code to ensure robust and error-free code. Step 1: Create a Simple Java Application Create a simple Java application, for example, “Copilot Demo,” and select Maven or Gradle as the build system through IntelliJ IDEA or Visual Studio Code. Step 2: Add JUnit Dependency For Maven: Add the following dependency to your pom.xml file inside the <dependencies> tag: XML <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.11.2</version> <scope>test</scope> </dependency> For Gradle: Add the following dependencies to your build.gradle file: dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.11.2' } Step ...