4

As a newbie to Drools, I'm confused about the differences between the mvel and java dialects and the relative pros and cons of using either.

After some initial research, I came across some discussions here, and here.

What other differences are there and what is the added benefit of using mvel over java other than syntactic sugar?

Thanks.

Community
  • 1
  • 1
dshgna
  • 790
  • 1
  • 14
  • 33
  • The last time I checked, MVEL lacked even such a basic feature as comments. So instead of commenting out some code during testing, you had to *delete* it. Conclusion: "thanks, but no thanks". – Marko Topolnik Feb 12 '15 at 09:09
  • There is no other benefit than syntactic sugar. The original author of MVEL has stoppen maintaining it; one guy from the Drools team has "inherited" the job. There has been a long history of bug fixing while Drools was beginning to make use of MVEL. It seems to be stable now, as far as usage with Drools is concerned. (Personal opinion: Why should I learn another syntax to code the same? The savings due to the "sugar" aren't exactly staggering.) – laune Feb 12 '15 at 10:18
  • I can see the point of using an expression language such as MVEL in the LHS/when side of rules. However, so far, I haven't been convinced of any benefit in enabling the dialect so that I could write MVEL in the RHS/then side of a rule. – Steve Feb 12 '15 at 13:11
  • "The last time I checked, MVEL lacked even such a basic feature as comments." MVEL does have comment support, as explained to you last time you said this in 2012. http://stackoverflow.com/questions/13516616/what-is-advantage-of-using-mvel – Mark Proctor Feb 13 '15 at 02:57
  • 2
    The original primary reason for MVEL was large rule based systems where generated bytecode was a problem - typically due to permgen issues. Decision tables could have 10K+ rules. Remember this was done back in 2007 (8 years ago), when permgen was a larger concern for some - especially those moving over from Jess (which was all reflection based). With MVEL everything is instances and refection based. The secondary reason was for a more compact friendly syntax. – Mark Proctor Feb 17 '15 at 22:33
  • That said, the dialect switch has made DRL difficult to tool, due to lack of consistency and creates ambiguity. We will be resolving this to a single language for the next revision of DRL. – Mark Proctor Feb 17 '15 at 22:35
  • @MarkProctor: Would this be either of MVEL or Java or a newer dialect? – dshgna Feb 18 '15 at 06:12
  • The term "dialect" referred to the idea of switching expression and block languages within patterns, evals and consequences. It also controlled how those were compiled and executed. We will push for a single language, that most likely targets JDT for compilation. Permgen is gone with java8, so the need for a reflection based language is diminished. We do not know what that language will look like yet. We want something more comfortable for java developers, for DRL, we also want to keep compact property accessors and over-rides of ==, as the make rules easy to read. – Mark Proctor Feb 19 '15 at 11:22
  • Anyone is welcome to join us in helping to design the syntax for a next generation rule language :) Instead of dialects, we want to make it easier for people to do language development - so we could potentially end up with a number of community owned languages, driven by our engine. http://blog.athico.com/2014/07/drools-executable-model.html – Mark Proctor Feb 19 '15 at 11:23

1 Answers1

8

MVEL is an Apache licensed powerful Expression Language (EL), written in Java for java based applications and hence its syntax is mostly similar to Java.

  • MVEL expression is clean and its syntax is easy to understand.
  • Apache drools use MVEL template for the dynamic code generation.
  • MVEL engine performance is good compared to other EL engine.

Consider an example.

    rule "validate holiday" 
    dialect "mvel"
    dialect "java"
    when
        $h1 : Holiday( month == "july" )
    then
        System.out.println($h1.name + ":" + $h1.month);
    end

The purpose of dialect "mvel" is to point the Getter and Setters of the variables of your Plain Old Java Object (POJO) classes. Consider the above example, in which a Holiday class is used and inside the circular brackets (parentheses) "month" is used. So with the help dialect "mvel" the getter and setters of the variable "month" can be accessed.

Dialect "java" is used to help us write our Java code in our rules. There is one restriction or characteristic on this. We cannot use Java code inside "when" part of the rule but we can use Java code in "then" part.

We can also declare a Reference variable $h1 without the $ symbol. There is no restriction on this. The main purpose of putting the $ symbol before the variable is to mark the difference between variables of POJO classes and Rules.

GauRang Omar
  • 761
  • 7
  • 17