Rules DSL versus Jython (JSR223)

Since joining the OH community in March, I’ve seen a recent uptick in posts about Jython; specifically, about converting Rules DSL to Jython equivalents. I’m curious if someone (looking at you @5iver and @rlkoshak) can articulate the pros and cons for non-programmers like myself. I have some ideas based on what I’ve read, but I haven’t found anything that summarizes the topic.

Please note that I don’t wish for this to turn into a debate about which is “better”. I’m just curious about Jython and am trying to determine if I should invest time into learning/testing/converting now, or if I should wait while development continues. I don’t have enough context to evaluate the pros and cons.

I’m asking for myself, and I’m also asking for the benefit of new users who might see us talking about both languages and wonder which way they should go. My sense is that it’s best for new users to stick with Rules DSL for now, since there are lots of people and years of examples to help them get up and running. However, if a new user already knows Python, perhaps they would be better off jumping right into Jython?

Thanks in advance for your insights!

Hah, and then I find @rlkoshak’s response in this post:

I read that thread when it was first posted, but didn’t think to return to it. Ironically, I thought about posting my questions there when I first read it, but thought it might be better as a separate topic.

I’m leaving this here in case anyone else wants to chime in.

I don’t really know where to start. In no particular order… (this will be a more thorough answer than that other thread as that answer was more personal (why am I converting my rules) and this question is more generic).

  • Thanks to the efforts of Scott and others, using the Helper Library, writing Rules in Jython at least (work is ongoing to bring JavaScript and Groovy up to speed) is almost as easy as Rules DSL now. There are a few areas where it’s less easy. For example, you have to install the Helper Libraries. The syntax is a little more arcane in my opinion, especially when dealing with Group members. But overall, it’s not significantly more challenging to learn. Another area where it’s less easy is at least with Jython, a whole bunch of types of errors are only discovered at runtime that Rules DSL catches at parse time (and therefore in VSCode).

  • The JSR223 languages will be the languages used to write Script Actions for UI created rules. Having a series of examples for writing Rules in these languages will also help those users. I predict that most non-coders will end up focusing primarily on the UI created rules so the examples will also help those users.

  • I predict that in OH 3, Rules DSL will be deprecated, or at best be one supported language among many. The default that will be covered in the docs and such will be the UI created rules instead of Rules DSL. By learning at least one of the languages now and posting lots of examples I can start to build up a base of support when that happens.

  • They load faster and they run faster than Rules DSL. And the Helper Library has built in a delay that avoids the problem with order of loading at OH boot.

  • They have the possibility of libraries and rule templates which are not possible with Rules DSL. Eventually I hope we can get to a place where most non-coder users don’t really have to write Rules themselves very much. They will download and configure them instead.

Would I recommend a non-coder choose a JSR223 Language right now? Maybe. I don’t think it will be much more difficult to learn over Rules DSL and the Helper Library Docs are currently at least as good as the Rules DSL Rules Docs. But there are fewer people on the forum who can help and fewer examples to draw from. I would probably recommend waiting until the replacement for PaperUI is released and then I’d recommend using that over Rules DSL because it will provide more opportunities to create reasonably complex Rules without writing a line of actual code.

But, if you want to learn something new or get ahead of the curve for changes that are coming down the line in the next six months to a year than experimenting with JSR223 would not be time poorly spent.

Personally, I plan on converting all my Rules to Jython, and then I’ll convert those to UI created Rules so I know the ins and outs of those and can be a resource to new users.

3 Likes

That’s a pretty good start! I had previously marked this thread as solved, but I’ve removed that in case others have thoughts to add.

This is actually the most compelling reason for me to convert my rules. I don’t have the coding expertise and experience of many other OH users, but I want to be able to help others when the time comes.