views:

329

answers:

5

I often need to implement some sort of rule system that is user-editable -- the requirements are generally different enough that the same system isn't directly applicable, so I frequently run into the same problem--how do I design a rule system that

  1. is maintainable
  2. properly balances expressiveness with ease of use
  3. is easily extended (if/when I get (2) wrong).

I think Rule systems / DSLs are extremely valuable, but I don't feel comfortable with my ability to design them properly.

What references / tips do you have to offer that may help make this easier?
Because of the nature of the problems I run into, existing languages are generally not applicable. (For example, you would not require that general computer users learn python in order to write an email filter.) Similarly, rule languages, such as JESS, are only a partial solution, since some (simpler) user interface needs to be built on-top of the rule language so non-programmers can make use of it. This interface invariably involves removing some features, or making those features more difficult to use, and that process poses the same problems described above.

Edit: To clarify, the question is about designing a rule engine, I'm not looking for a pre-built rule engine. If you suggest a rule engine, please explain how it addresses the question about making good design decisions.

+1  A: 

We have had luck with this: http://msdn.microsoft.com/en-us/library/bb472424.aspx

Bloodhound
A: 

A Ruby implementation to consider is Ruleby (http://ruleby.org/wiki/Ruleby)

Jay Shepherd
A: 

One thing I've found is that being able to define rules as expression trees makes implementation so much simpler. As you correctly mentioned, the requirements from project to project are so different that you just about have to reimplement every time. Expression trees coupled with something like the visitor pattern make for a very (no pun intended) expressive framework that is easily extensible. And you can easily put a very dynamic GUI on top of expression trees which meets that aspect of your requirement.

Hopefully this doesn't sound like I'm saying that everything looks like a nail with my hammer because that's not the case ... it's just that in my experience, this has come in handy more than once :-)

Joel Martinez
I'm not sure I understand the applicability of expression trees. Are you suggesting them as an aspect of the rule language interpreter, or do you use them to represent the options for each rule? I'm a little confused.
rcreswick
A: 

First of all, normally it is not advised to let end-users define the rules. That's because they do not have development background and could simply write "code" that goes into infinite loop or does other weird things.

So either the system has to protect against that kind of behavior (thus, making it more complex), accept such possibility, or disallow end-users to do this.

If you are working with .NET then it is hideously easy to create your own DSL by extending the Boo compiler (i.e. with Rhino.DSL you can have simple DSL with one class).

Rinat Abdullin
+2  A: 

We had an in-house demo of this tool by it's vendor: http://www.rulearts.com/rulexpress.php

As a company, we have a lot of experience with rule engines (e.g. Cleverpath Aion), but mostly developer-oriented tools. This tool (rulexpress) is very business-people oriented. It's not a rule engine. But it can output all the data in xml (so basically any format you like), and this is something we would then consider as input for a real rule engine, e.g. Windows Workflow Foundation (not one of the bigger/better rule engines, but still).

The tool in itself looked pretty good, some stuff I had never seen in any developer-oriented tool.

There are also some tools for rule management built around WF, if that's your rule engine of choice, check out InRule.


Edited after original question was clarified: Although I have dabbled in this a long time ago (writing a little language in javacc), I would consider this a bad time investment now. My comment above is in the same spirit: take a simple rule engine, a simple (commercial) UI that makes it easy for business users to maintain, and only invest time in tying the two together.

StephaneT