<img height="1" width="1" style="display:none;" alt="" src="https://px.ads.linkedin.com/collect/?pid=1195114&amp;fmt=gif">
Close

Code reviews: How to get started? | CLEVR

Published 11-12-2019, last updated 01-02-2024 3 min read
Blog overview Image

The Application Code Reviewer (ACR) is a tool built for developers to help with code review. It scans a Mendix project and detects potential bugs, smelly code, security vulnerabilities and more. ACR does this by comparing a Mendix project against a database of development rules based on Mendix best practices and community guidelines. 

Automatic code reviews deliver the best value when used by team members during development and ideally as part of a continuous integration pipeline. This post tries to look at some strategies on how to best adopt ACR and get the most benefit out of it.

When to do code reviews?

Code reviews should be done as early as possible in the development cycle. Ideally, when development on a user story is finished the developers should scan their Mendix project for violations and fix them before committing to the team server. This keeps the code base clean.

In addition to manual scans done by developers, it is recommended to do at least one scheduled scan per day. Schedule this scan to run at the end of a work day against the latest revision. This gives representative historic data for the code quality of the project over time.

Trends since begining of time

The trend-line shows the number of violations per category for each revision.

Using ACR on a project

When introducing any tool to a project it makes a big difference if this is a new or an existing project (also called green and brown field respectively).

Green field projects

So you are starting a new project from scratch. Lucky you! And you have decided to do this one right, so it has to have CI/CD, testing, code reviews, etc. You know all the good stuff that every project needs to be a success. Using ACR on a green field project is fairly straightforward.

As soon as ACR finds a rule violation fix it asap or add it to the white-list. In terms of overall code quality, try to keep module encapsulation to above 60-80 percent and size to medium and finally aim for 80-60 code coverage. If module encapsulation drops too much then its time to put on your refactoring hat. When a module becomes too big consider peeling off functionality or splitting it, divide and conquer style. If test coverage is too low, well.. then write more tests.

Brown field project

The challenge with using ACR on an existing project is that the initial scan will reveal hundreds or maybe even thousands of violations. This is only logical, since a project that has seen active development without an automated code review tool, accumulates violations over time. To fix all the violations could take weeks. However, it is often not possible to justify stopping all active development for several weeks to fix violations that only developers can see. The solution is to adopt the ratchet methodology.

a ratchet

A ratchet is a mechanical device that allows motion in only one direction while preventing motion in the opposite direction.

With this methodology developers are required to keep the total number of violations in the project either the same or lower with every new version. This serves a dual purpose. For one, new code will tend to have very little violations. On the other hand developers will work towards fixing violations in existing code gradually as a safe guard, to keep the total lower in case the new code that they write triggers a violation.

It has been shown that projects that adopt this methodology see a gradual, but continuous reduction in the number of violations over time and with that increase in the code quality.

Communication and fostering adoption

In order to successfully introduce a new tool to your development workflow communication is essential. Make sure that all teams and all team members are aware of the existence of the tool and where to find it. Everyone should know what the tool can do for them; when they are expected to use it and how they need to act on findings from the tool.

In some cases certain team members struggle to adopt or flat out reject static code analysis, due to skepticism. I personally was once a non-believer. To overcome this, pick a few violations from that developers latest revision discovered by ACR and go to that developer and show them what ACR found. The developers will either fix the violations or start a discussion about what development rules are checked. In any case, that developer will start paying more attention to ACR in the future.

Summary

Doing an automatic code review early during development is one of most effective ways to improve code quality. When dealing with existing or legacy project use the ratchet methodology and focus on newly discovered violations. Finally, establish goals for quality, e.g. over 60% module encapsulation, and communicate them clearly with the entire development team.

I hope you enjoyed reading this post and that it helps you to build better applications. If you have any questions, please feel free to contact me.

CLEVR CLEVR, a globally recognized provider of low code, Product Lifecycle Management (PLM), and Manufacturing Operations Management/Manufacturing Execution Systems (MOM/MES) software solutions, specializes in enabling organizations to unlock their full potential through digital transformation. By combining cutting-edge technology with industry expertise and a customer-centric approach, CLEVR delivers comprehensive software solutions that drive innovation, accelerate growth, and provide organizations with a competitive edge in the rapidly evolving digital landscape.
Read the latest CLEVR news, articles and updates on LinkedIn
Receive personal news and updates in your inbox
contact-icon--white Get in touch

Get in touch

Do you want to know more about our CLEVR solutions and services? Please leave your contact details in the form below, write an email or visit us in one of our CLEVR experience centers.