Fork me on GitHub
#clara
<
2022-04-24
>
Bo Han08:04:54

hey everyone, pretty new to clara rules here - using it to do something similar to the shopping example but more complicated. are there some common code smells / antipatterns to avoid when writing rules? for example, i found myself using 'test' at first for scenarios where there was a more elegant option.

apbleonard09:04:14

Perhaps avoid putting logic in the RHS? Also try to avoid thinking about your logic in a way that is similar to a case statement, which is inherently ordered. Split the apparent case statement into separate rules with all necessary conditions. If multiple rules are firing where only one should either add more conditions to make them clearly mutually exclusive or implement query logic detecting "conflicting" or "inconclusive" results.

apbleonard09:04:25

Also perhaps avoid facts with long names such as thisAndThisAndThat. These names suggest there may be a more "primitive" and useful fact hiding in there that can be used with rule conditions providing the equivalent "And" parts to infer more facts as required :)

👍 1