<p>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</p>

<ol>
<li>is maintainable</li>
<li>properly balances expressiveness with ease of use</li>
<li>is easily extended (if/when I get (2) wrong).  </li>
</ol>

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

<p>What references / tips do you have to offer that may help make this easier?<br>
Because of the nature of the problems I run into, existing languages are generally not applicable.  (For example, you would <em>not</em> require that general computer users learn python in order to write an email filter.)   Similarly, rule <em>languages</em>, such as <a href="http://herzberg.ca.sandia.gov/" rel="noreferrer">JESS</a>, 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 <a href="http://herzberg.ca.sandia.gov/" rel="noreferrer">process</a> poses the same problems described above.</p>

<p><em>Edit:</em> To clarify, the question is about <em>designing</em> 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.</p>

[{'answer_id': 67493, 'author': 'Mike Becatti', 'author_id': 6617, 'author_profile': 'https://Stackoverflow.com/users/6617', 'pm_score': 1, 'selected': False, 'text': '<p>We have had luck with this: <a href="http://msdn.microsoft.com/en-us/library/bb472424.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb472424.aspx</a></p>\n'}, {'answer_id': 67495, 'author': 'Jay Shepherd', 'author_id': 7511, 'author_profile': 'https://Stackoverflow.com/users/7511', 'pm_score': 0, 'selected': False, 'text': '<p>A Ruby implementation to consider is Ruleby (<a href="http://ruleby.org/wiki/Ruleby" rel="nofollow noreferrer">http://ruleby.org/wiki/Ruleby</a>)</p>\n'}, {'answer_id': 67511, 'author': 'Joel Martinez', 'author_id': 5416, 'author_profile': 'https://Stackoverflow.com/users/5416', 'pm_score': 0, 'selected': False, 'text': "<p>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.</p>\n\n<p>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 :-)</p>\n"}, {'answer_id': 152451, 'author': 'Rinat Abdullin', 'author_id': 47366, 'author_profile': 'https://Stackoverflow.com/users/47366', 'pm_score': 0, 'selected': False, 'text': '<p>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. </p>\n\n<p>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.</p>\n\n<p>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).</p>\n'}, {'answer_id': 152532, 'author': 'stombeur', 'author_id': 23697, 'author_profile': 'https://Stackoverflow.com/users/23697', 'pm_score': 2, 'selected': False, 'text': '<p>We had an in-house demo of this tool by it\'s vendor:\n<a href="http://www.rulearts.com/rulexpress.php" rel="nofollow noreferrer">http://www.rulearts.com/rulexpress.php</a></p>\n\n<p>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).</p>\n\n<p>The tool in itself looked pretty good, some stuff I had never seen in any developer-oriented tool.</p>\n\n<p>There are also some tools for rule management built around WF, if that\'s your rule engine of choice, check out InRule.</p>\n\n<hr>\n\n<p>Edited after original question was clarified:\nAlthough 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.</p>\n'}]
['https://Stackoverflow.com/questions/67475', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3446/']