BC Friday Tips #12 Code with Clear Intention

It’s time for #BCFridayTips for #msdyn365bc developers!
Code with Clear Intention.
When youโre writing a code, itโs not just you who will read it. Itโs important to ensure your intentions are crystal clear.
Let’s look at an example:
๐ฅ๐ฒ๐ฐ๐ผ๐ฟ๐ฑ.๐ ๐ผ๐ฑ๐ถ๐ณ๐(๐ฅ๐๐ป๐ง๐ฟ๐ถ๐ด๐ด๐ฒ๐ฟ)
The RunTrigger parameter is optional. If left unspecified, it modifies a record without executing the code in the OnModify trigger.
While itโs best practice to run the trigger, there are times and valid reasons when you might not want to.
Instead of:
Record.Modify();
Use:
Record.Modify(๐ณ๐ฎ๐น๐๐ฒ);
Why?
โ ๐๐น๐ฎ๐ฟ๐ถ๐๐: Being explicit is better than being implicit. In this case, the intention is not to run the trigger.
โ ๐๐๐ผ๐ถ๐ฑ๐ถ๐ป๐ด ๐ฎ๐บ๐ฏ๐ถ๐ด๐๐ถ๐๐: Record.Modify() could mean two things: You either donโt want to run the trigger, or you forgot to run it.
โ ๐ ๐ฎ๐ถ๐ป๐๐ฎ๐ถ๐ป๐ฎ๐ฏ๐ถ๐น๐ถ๐๐: Without the parameter, another developer might assume you made a mistake and try to fix it by running the RunTrigger, which could introduce bugs.
Always remember that even minor things can make a difference.
Donโt forget to share this post with others โป๏ธ and follow for more tips in future. ๐