Monday, December 2, 2019

Pega when condition : Logical AND short circuit

Consider a scenario where you have to code when condition in Pega where both the conditions (Condition1 and Condition 2) should be satisfied to identiy if it is a valid record.

Condition1 : D_HeavyPage.IsValid = true // D_HeavyPage is page which takes some time to load
Condition2 : .IsAvailable = true        // Simple top level property

Then a developer coded the when rule (IsValidRecord) as below :




Let's take a closer look to identify if the above code is up to the standard. Well w.r.t functionality, it would work. But performance is there any chance of improving it ?

Logical AND follows below table for evaluation.

true  AND true  = true
true  AND false = false
false AND true  = false
false AND false = false

A AND B => If A is false, it wont evaluate B which saves some time for us.
In this case A is heavy operation for us as data page has to be loaded to check the property is true or not. So it would help the performance if we reverse the when condition as B AND A



Which means => If B is false, it won't even evaluate A which saves lot of time for us.
Note: This convention is same across most of the programming languages like JAVA, ...

1 comment:


HowToPega : All rights reserved and the contents are copyrighted to Pavan Kumar Naidu