On the use of Priorities and Control facts in rule-based programming

As rule-based programming is becoming more and more mainstream, it is important to re-emphasize some of the basic patterns.

One of the features that have been introduced since the early rule languages, particularly in production systems, is the control of rules ordering and execution. This can be achieved with a salience (also called a priority, often a static integer value, sometimes dynamically calculated), a control fact (a fact that is not representing a piece of knowledge but used to control the firing of rules), or modules (containers of rules).

Normally, when a rulebase is designed and coded efficiently, there is no need for the use of priorities or control facts. However, in the practical real-world of programming, this is not always possible. As a design pattern, avoid using many levels of priorities (depending of the size and complexity of your application, 3 to 5 should be a maximum). There are a number of other approaches that have been studied. The use of declarative priorities such as the overrides predicate that has been introduced in RuleML 0.8 (work by Benjamin Grosof, MIT) is a possible candidate that I will discuss later along with other solutions.