Logic-grid conditional
From Wiki @ Karl Jones dot com
A logic-grid conditional is a conditional (computer programming) which uses arrays and bitwise operations.
Description
Narendra Venkataraman writes:
Deeply nested if-else and giant switch statements are a common sight in any complex logic implementation. Maintaining such a messy chunk of code is really a nightmare.This technique comes in very handy in implementing rule engines and finite state machines (FSM).
Typically, any logic has a set of boolean predicates that are evaluated to obtain a result or to perform an action.
In the logic-grid approach, the results are stored in an array and the index of the array is calculated from a bitwise combination of boolean predicates.
The key to this approach is that the logic is embedded into data instead of sequence of logic statements. Thinking beyond the bits and bytes, the approach draws parallel with the way people make decisions. We evaluate all the inputs available at a moment and make the best possible decision.
See also
- Array data structure - a data structure consisting of a collection of data elements (values or variables), each identified by at least one array index or key.
- Conditional (computer programming)
External links
- Logic-Grid: An Elegant Alternative to Your If-Else Nightmare! by Narendra Venkataraman - posted April 19th, 2005