Ask HN: Would you implement a decision table library, in 2015?
Would you really implement a decision table library in 2015? Would you actually use decision tables in your application or push for other alternatives?
Thanks a lot!
Would you really implement a decision table library in 2015? Would you actually use decision tables in your application or push for other alternatives?
Thanks a lot!
My basic starting thoughts is that if the rules are well known, change infrequently, have minimal nested chaining and number < 50 or so then I'd opt for having a good design pattern or simple if/else within the code. If you violate any of these tenants, then I'd look at decision tables/trees first, then after that move to a rules engine. Of course, if users are required to write their own then that would also have to factor in to this decision. BTW -- Don't dismiss a good design pattern or even a plug-in pattern as sometimes that is more than enough to solve moderately complex rules without adding additional dependencies or significant development complexity.
If this is an application that will be deployed to third party sites, then again, I generally opt for a balance between the number of dependencies and the application maintenance. If it is deployed behind a website or application where your company controls the environment, then I focus more on flexibility and application maintenance than dependencies.
Also, in a few less common scenario's, I have written very basic purpose built rules engines that solved some of the key issues without creating needless complexity, maintenance or dependency nightmares. Not that I advocate writing libraries/code that already exists, but many times you just don't need a Drools, or ilog rules etc. Also, this is where something like embedded JavaScript is a handy tool as pjungwir also mentioned.
More often I see people take this approach to let end users compose rules for various actions. But this kind of thing tends to be what I call a "Turing complete" feature, where people are always writing rules that go beyond what your model can express. ("If there are two of these, and one is not older than this, and their mean is greater than the most recent of these, and the current time is before 8 a.m. in the time zone of the user who owns this user's account . . .")
In that case, if your users are sophisticated enough (e.g. internal users in a "services" division of your company), you might want to consider going with embedded Javascript instead. You can expose a few objects/functions from your application and let people write JS using them. Then you run their JS and see if it evaluates to true. I've used this in a Ruby context before with the gem therubyracer.
This is nice because your app gets a full-featured scripting language for free. You don't have to design the language or write an interpreter. Javascript is designed to be very secure. It can't do IO or run shell commands. And it's probably the most widely-understood programming language out there, so there's a low learning curve.
Challenges are that your users have to understand a programming language, and you'll probably want to take steps to validate the Javascript they're writing and to surface decent error messages when problems happen. Also therubyracer can use a lot of memory, which may or may not be a concern depending. Another challenge is that the JS will be opaque to an outside computer system. It's hard to break it down and express what it's all about. For instance you couldn't run a query to find all actions that require condition foo.
Good luck!
http://docs.jboss.org/drools/release/5.3.0.Final/drools-expe...