Fog Creek Software
g
Discussion Board




Rule-driven GUI's

Hello,

I'm curious if anyone has any experience with using rule-based (business rules, RETE, etc) systems to drive GUI logic.

For example, instead of having code attached to the click event of a Cancel button, the button would input the event into the rule pool where one or more rules would fire, and close the window, or whatever is called for.

Is this sort of logic popular at all? I've done some searching on Google/Yahoo/etc., but haven't seen much.

I've been looking at rules systems for Java, specifically Drools. Seems like it would be a good fit for this sort of thing .

NC
Thursday, February 19, 2004

I've taken this approach in a couple experimental systems in years gone by, and honestly it worked very well.  On the other hand, integrating this approach with common GUI packages would be very tedious and challenging, I would imagine.

As another application of rules being used in the GUI, I've used them to drive a layout engine with pretty good results, also in experimental systems.

my two bits
Thursday, February 19, 2004

I'm curious as to what sort of benefits you hope to gain from this.  Why is having a message driven system based off of rules so that an outside component closes your dialog box for you better than having the two lines of code hard coded to the dialog box to close it for you?  I don't see what you hope to gain from this.  All I see is a difficult system to program with an incredibly steep learning curve that may or may not plateau, that takes up more disk space, more memory, and more CPU cycles for the same end user effect.  I only ask as I've had some experience working with such nightmarish type systems, although my nightmare seems to be no where near the horror of a dream that you describe.

Elephant
Thursday, February 19, 2004

They had a rule-based Pensions system where I contracted last year. I believe the product was ok but the company that provided it were absolutely crap and never seemed to test anything. We were normally getting about a patch a day!

However, it was sold as a rule based pensions system but I don't think it ever got to the point where it could be tailored by the data alone and consequentl new business rules often required code changes too..

From this and other experience I have come to the conclusion that any rule-based system you develop is always going to have to be a compromise and you're never going to be able to tailor it how you want.. either that or it's so tailorable that you might as well be writing code for all the rules you have to put in!

Gwyn
Thursday, February 19, 2004

This reminds me about something my boss at the time said when I was working on such a system.  I developed some code for developing custom reports.  It was a bit different then described, as plugins did require coding... anyhow, I had an XML report descriptor file that spelled out fields, formatting, etc.  I required that the dev implement three functions, one for filling in the field, one for should a section be processed, and should the section be itterated.  Anyhow, my boss asks me if I can narrow it down to two functions to implement because he thought three was simply asking for a lot of work.

Granted it's a stretch, but extrapolating his reasoning out across the entire middleware layer we were working on, I figured that he'd want all decions answered with a yes or no response.  1 or 0, back where we started if you follow.  All that time, millions of lines later, may as well done nothing to begin with.  I think the irony of the situation was lost on most people on my team.  Oh well, maybe I just have a peculiar sense of humor.

Elephant
Thursday, February 19, 2004

Elephant (and others),

To answer your questions -- I really don't know.

I have rules experience in other areas, and this seemed a *possible* extension, though perhaps not a good one.

Agreed, you raise very good points. I'm just on a curiosity fishing expedition here.

As two-bits commented, it can be very handy with layout problems, and similar problems. If the rule-base is already there, why not look at using it in different ways?

NC
Thursday, February 19, 2004

NC,

This definitely is a possibility in Java as long as you're careful about not integrating your behavior code in your GUI code.

Just create an action that does what you need and have all relevent GUI components register as listeners to it.

Crimson
Thursday, February 19, 2004

Ackkkk noooo.....!!!!!

I built a GUI using a rule-driven expert system (ART on a Symbolics workstation. Old stuff.)

As soon as you try to do anything reasonably complicated, you have to start setting priorities for various rules to make sure things happen in the right order.

Suddenly you find yourself with lots of rules at different priorities, and, effectively, it's like BASIC with line numbers, only the line numbers are in reverse order (higher priority fires first). Unbelievably unclean mess. The thing I was doing was a small project so it survived but anything larger would have collapsed under its own weight.

Joel Spolsky
Fog Creek Software
Thursday, February 19, 2004

You get the same problem you have with large
complicated prolog programs. Order becomes
unpredictable and you will never know exactly
what will happen. You start having to add in cuts
and other magic to add back in predectable
sequencing.

son of parnas
Thursday, February 19, 2004

If you are thinking of a system like this I'd suggest you start with a bit of research. The AI community has tons of experience in rule based systems (expert systems or knowledge based systems). A bit of reading now will save you a lot of hassle later.

Joel's problem with priorities is a good example of something you'd know to avoid with a bit of research. Priorities are known not to scale and should avoided. Instead use a simple dependency system will deal with the rule ordering.

John Eikenberry
Thursday, February 19, 2004

Without knowing the details of any of the horror stories mentioned above, I suspect at least some of the problems stem from poor design.  Just as there are "code smells" in Java or C# code, there are "smells" in rule driven systems.  Heavy reliance on sequencing and priorities is one of the most prevalent.

Also, I wouldn't recommend trying to code an entire GUI system as rules.  There are parts of GUIs that are definitely best left to imperative style program fragments.  The executive functions that coordinate things and maintain state are excellent candidates for encoding as rules (i.e. is control-x currently active?).  Processing functions and other algorithmic requirements are almost always better handled using other mechanisms, though.

Rule systems require a fundamental shift in the way you think about solving problems.  They are a little difficult to wrap your thinking around at first, but once you understand them, they can be a powerful tool in your toolbox.  Why not do a few simple tests for yourself, and see what you think?

my two bits
Thursday, February 19, 2004

Joel, your problems were caused by ART, not rule based coding.

You would have had a much different experience using Guru or KB/C. Even VP-Expert would have given you a better application model.

HeWhoMustBeConfused
Thursday, February 19, 2004

It probably doesn't qualify as a rules-driven system, but I saw an excellent discussion on building GUIs (and widgets/controls specifically) using a production system. The nice thing was that the setup was such that it was fairly easy to take the production rules and generate the underlying GUI code.

I, unfortunately, don't remember which book it was in right now. If anyone's interested, I have it at home.

Chris Tavares
Thursday, February 19, 2004

Chris,

Yes, I would like to know.

Karel Thönissen (www.hello.nl)
Thursday, February 19, 2004

Second that Chris. I'd be very interesting.

Thanks.

NC
Friday, February 20, 2004

Of course I'm interesting, but I'm interested as well :)

NC
Friday, February 20, 2004

I found the book. It's here:

http://www.bookpool.com/.x/ehqeo5nnp6/sm/1558604189

The discussion I was referring to was in Chapter 8. This was the textbook for a gui class I took a few years ago. I can probably come up with more information, but it'll take a couple of days for me to get it together.

Chris Tavares
Friday, February 20, 2004

*  Recent Topics

*  Fog Creek Home