How to find Repeting AL Code in your solution

Duplicate code as the name suggests is a repetition of a line or a block of code in the same file or in the same project. People might consider code duplication acceptable but in reality, it poses greater problems to your software than you may have thought. 

The main reason for the creation of the duplicate code is Copy and Paste Programming. 

Some reasons why not to do it:

  • Duplicate code makes your program lengthy and bulky
  • Duplication decreases your code quality 
  • Suppose you write buggy code. You do a code review to find out the issue and then fix it. Now replace this scenario of buggy code with duplicate buggy code.

How to detect code duplication?

A while ago AZ AL Dev Tools has released a new command called “Find duplicate AL code”. It helps you a lot especially when you are working on refactoring your (or someone else) code.

To use it, open the command palette and type Find Duplicate AL Code.

Specify the minimum no. of statements to be considered as duplicate.

The command will search your current project and open a panel with list of duplicate code blocks and code locations.

When you click on one of locations, it opens the file and highlights the code in the editor.


How to remove duplicate code?


One of the solutions would be that, duplicate lines of code should be replaced with a single method, by encapsulation of the code. So the fix would be to extract the method and call from the places where it has been used.



Share on facebook
Share on twitter
Share on linkedin