﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Kris commented on A rule engine in less than 70 lines of code</title><description>This looks really cool.  It would be great to see a Hibernating Rhinos episode one day.  BTW, thanks for the excellent video casts, it's been great to watch these as they are very informative and interesting.  Your Resharper chops are truly impressive!  I lost some of my skills after working in Eclipse all of last year!
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment7</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment7</guid><pubDate>Tue, 11 Dec 2007 05:54:09 GMT</pubDate></item><item><title>Joe Ocampo commented on A rule engine in less than 70 lines of code</title><description>This is really impressive.  I like how you added the "When" keyword and the then statement is inferred by statement block.
  
  
I am going to have to check out this code.  Nice job.
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment6</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment6</guid><pubDate>Tue, 11 Dec 2007 04:55:14 GMT</pubDate></item><item><title>Ayende Rahien commented on A rule engine in less than 70 lines of code</title><description>The logic in the script is that the first one to match is the one that is being evaluated.
  
I am using boo file per policy here, yes.
  
Another option would be to define:
  
  
rule 'name':
  
   when ...
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment5</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment5</guid><pubDate>Tue, 11 Dec 2007 03:41:56 GMT</pubDate></item><item><title>Tomas Restrepo commented on A rule engine in less than 70 lines of code</title><description>Sorry, I wasn't very clear. I was probably presuming much from your small code snippet, so don't pay much attention to me about that. (I was thinking along the lines that the way your example calculates the "freeShipping" option didn't make much sense).
  
  
Chaining is more useful in slightly more complex scenarios were the rule applications have side-effects that can invalidate other rules in the policy (or make valid previously invalid rules).... this is useful, but can also be a performance drag (or introduce unwanted cycles). In most rules-based systems like that you don't really apply rules, but entire policies (you probably know that already), which, in your case, I'd guess would be a complete .boo file.
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment4</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment4</guid><pubDate>Tue, 11 Dec 2007 03:23:57 GMT</pubDate></item><item><title>Ayende Rahien commented on A rule engine in less than 70 lines of code</title><description>Tomas,
  
Can you explain why I have a single rule defined three times? I see only a single rule.
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment3</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment3</guid><pubDate>Tue, 11 Dec 2007 02:40:15 GMT</pubDate></item><item><title>Tomas Restrepo commented on A rule engine in less than 70 lines of code</title><description>Yep, Scott is right on the money; this kind of thing would be far more suitable to a policy, and actually chaining can make it easier to define them. For example, notice that your example actually has a single rule defined three times, whereas if you had chaining you could have it a single time.
  
  
BTW, you can actually invoke the WF rules engine outside of WF, so I guess that might be useful on it's own (though I haven't had a chance to use it like this yet).
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment2</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment2</guid><pubDate>Tue, 11 Dec 2007 02:30:42 GMT</pubDate></item><item><title>Scott Allen commented on A rule engine in less than 70 lines of code</title><description>Try the PolicyActivity instead. You could put all those rules into a single ruleset for the PolicyActivity to evaluate and it will take care of managing priorities, and forward chaining on any intra-rule dependencies.  There are other pros (and cons), but its a better fit than a sequential workflow (you don't want to control the flow of execution, you want the execution to evaluate declarative knowledge). 
</description><link>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment1</link><guid>http://ayende.com/3033/a-rule-engine-in-less-than-70-lines-of-code#comment1</guid><pubDate>Tue, 11 Dec 2007 02:15:51 GMT</pubDate></item></channel></rss>