<div dir="ltr">   Thomas,<div><br></div><div style>   Pluggable operators were developed much before we supported free form expressions, but nowadays they can be used for the same purpose. It is then a matter of preference basically. You can still develop and use pluggable operators if that makes your rule more readable by hiding complexity related to parameter passing or something that would be required in a method call, but I can&#39;t think of any advantage or disadvantage in either approach in terms of performance or cost.</div>
<div style><br></div><div style>   If I remember correctly, pluggable operators were developed for Drools 4.0, while free form expressions were only fully functional in 5.3+ (limited functionality in 5.2).</div><div style>
<br></div><div style>   Edson</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, May 24, 2013 at 10:54 AM, Thomas Grayson <span dir="ltr">&lt;<a href="mailto:tgrayson@bluemetal.com" target="_blank">tgrayson@bluemetal.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div>
<p class="MsoNormal">What are the benefits of using pluggable operators (implementations of org.drools.base.evaluators.EvaluatorDefinition such str, matches, or before) versus simply making an equivalent function call?  I’ve read the
<a href="http://blog.athico.com/2010/06/creating-pluggable-oprators.html" target="_blank">Creating pluggable operators</a> blog post.  Apart from saying that the Eclipse plugin can recognize these operators, it doesn’t really make a case for why I’d want to create my own implementation. 
 One might argue that operators enhance reusability, but a static method offers much the same benefit.  Does a pluggable operator have any optimization, caching, or other advantage?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">For example, here are two ways to match the start of a string in a property of a fact, one using  the “str[startsWith]” operator and another with Java’s String.startsWith method:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">declare</span></b><span style="font-size:10.0pt;font-family:Consolas"> Fact</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">    key : String @key</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">end</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">rule</span></b><span style="font-size:10.0pt;font-family:Consolas">
</span><span style="font-size:10.0pt;font-family:Consolas;color:green">&quot;Use operator&quot;</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">   
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">when</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">        Fact(key str[startsWith]
</span><span style="font-size:10.0pt;font-family:Consolas;color:green">&quot;abc&quot;</span><span style="font-size:10.0pt;font-family:Consolas">)</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">   
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">then</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:olive">// do something</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">end</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas"><u></u> <u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">rule</span></b><span style="font-size:10.0pt;font-family:Consolas">
</span><span style="font-size:10.0pt;font-family:Consolas;color:green">&quot;Use method&quot;</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">   
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">when</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">        Fact(key.startsWith(</span><span style="font-size:10.0pt;font-family:Consolas;color:green">&quot;abc&quot;</span><span style="font-size:10.0pt;font-family:Consolas">))</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>

<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">   
</span><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">then</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:Consolas">       
</span><span style="font-size:10.0pt;font-family:Consolas;color:olive">// do something</span><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal" style="text-autospace:none"><b><span style="font-size:10.0pt;font-family:Consolas;color:#960000">end</span></b><span style="font-size:10.0pt;font-family:Consolas"><u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Does one of these perform better than the other?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Best wishes,<u></u><u></u></p>
<p class="MsoNormal">Tom<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>

<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>
  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>
</div>