The formulas for Rules are based on simple, familiar expressions that return a value. The language used for formulas is based on JavaScript, which is widely used for web applications.
You don’t need to be an expert in JavaScript and we’ll show you most of what you need to know with a few examples. Answers to additional questions about JavaScript are easy to find on the web.
kBridge includes some pre-built JavaScript functions and we have enhanced the syntax to make it easier to write typical Rules. However, ultimately it is a JavaScript expression that must return a single value.
Note that, except for the special type of Rule called a method, a Rule is not a function and there are no inputs to its formula. It calculates its value purely by referencing other Rules or by calling functions. These references set up the dependencies between the Rules. Those dependencies are always one-way, from the current Rule, to the referenced Rule.
One-way constraints
This restriction to one-way dependencies is important. It enables kBridge to be very efficient in calculating the result (a model) for very large and complex Designs. However, this also means that it does not ‘solve’ systems of two-way constraints. Although there are legitimate uses for solving optimization problems that involve two-way constraints, we leave that to external or 3rd party systems when it is necessary. What we have found, however, is that there is a very large class of Design automation problems that can be very efficiently solved using the one-way constraint approach.
Note also that external references in the formula generally must be actual Rule references. References are detected and tracked by the kBridge Rules engine. For example, if our Rule for Width is Length / 2, then a dependency is established between Length and Width; if Width changes, then kBridge knows that it must follow the dependencies on Width (in this case, Length) and also execute changes on those as well.
External sources are not automatically updated
Although there are some legitimate reasons to call external programs or data via a Rule, note that those calls are normally not tracked by the kBridge Rules engine and will not update automatically when the source program or data changes. For example, a Rule could reach out to get a value from a database. The initial calculation will work fine. However, if the referenced value in the database changes, there is no way for kBridge to know that and update itself automatically.
Note also that it is not allowed for one Rule to set the value of another Rule. Each Rule must calculate its own value. This is a common mistake made by people who are very familiar with programming in general but have never used a declarative system like kBridge. Non-programmers don’t even imagine that they can set another Rule’s value and don’t generally ever run into this problem, so those of you who are programmers out there, beware!