[Catalyst] Re: Controllers vs Models

Justin Tocci jtocci at tocci.org
Mon Jun 6 18:57:49 CEST 2005

> Basically, you are talking about reducing the Controller to a pure  
> dispatch role--it accepts events from the external world and  
> forwards them to the business logic component.
> Although this is good in theory, what it really amounts to is  
> another layer of indirection with associated overhead.  The code to  
> handle dispatch is pretty minor--especially in Catalyst, where it  
> pretty much just consists of putting an attribute on the subroutine  
> that implements the business logic.  I don't see what win you are  
> looking to get by this separation.
> Well, maybe I do...you are saying you want to have the logic in the  
> DB, and have the controller fetch it out as needed.  This is often  
> called SCID programming (Source Code In Database), and it has some  
> powerful potential, although I personally have never seen a good  
> implementation of it.

Actually I'd rather see the rules in a simple file than in the database.

> In this case, the problem is that either (A) the Controller will  
> need to have enough knowledge of the business logic to know what to  
> fetch (at which point you might as well have just put the business  
> logic directly in the Controller and saved a DB access), or (B) the  
> Controller must simply dispatch the request to the business logic  
> component and say "here, I got this...figure out what to do with  
> it."  Option B is exactly what Catalyst does now, so this just adds  
> a redundant dispatch cycle.

(B) is definitely what I'm looking for. The controller fetches an  
object that has some variable built into it, it checks the rule file  
for how to evaluate it, fills it in, then sends the component off.

>> Example:
>> You have a View component that should act a little differently  
>> sometimes. For instance, a list page component should have a  
>> different title depending on which table it is displaying. One way  
>> to do it would be to have a separate component for each, another  
>> might be to put logic in the View that picks a different title  
>> based on the name of the table it is displaying. Another might be  
>> to put the logic in the controller.
> Another would be to use a template (c.f. Template Toolkit,  
> HTML::Mason, etc), where the title is filled in from a variable.   
> This is the way Catalyst currently does it.  I think this is  
> exactly what you're looking for--the "business logic" (i.e., what  
> title to use) is in the template file on disk, not in the View (or  
> Controller, or Model) class.

I'm trying to factor that out of the template to make the template a  
strictly generic reusable object. I'm trying to imagine one place  
where all the logic of how to determine the values for those  
variables would be stored, and if necessary, manually overridden.

> This is called (logically enough) "rules-based programming" and  
> there are entire languages written around it...e.g. Prolog.
> Based on my limited experience of it, RBP is really, really hard.
> The problem is that there is no clear control flow; the easiest way  
> to think of it (for me) is from a quantum mechanical standpoint:   
> every rule represents a probability of some particular outcome.   
> The rules engine takes all the rules, superimposes them into a  
> unified waveform, and then collapses that waveform into a single  
> outcome.

You're a good writer you know that? Many couldn't have explained such  
a concept so succinctly.

> How exactly you got that particular outcome is hard to track.   
> Which rules fired?  In what order?  For example, in your list  
> above, you have 'easy_money' display as 'Easy Money' because the  
> 'substitute underscore' and 'capitalize name' rules fired in that  
> order.  If they had fired in the opposite order, then 'easy_money'  
> would display as 'Easy money'.  How do you ensure that these rules  
> fire in the correct order?

Sorry, you are right. The capitalization rule should have had a  
higher priority than the under bar rule:

Example default rules:
10 column name should substitute under bars with spaces
10 IF column type is 'date' THEN display format is 'mm-dd-yy'
15 column name should be capitalized

Custom rules:
100 IF column name is 'nasa' THEN display 'NASA'
100 IF column name is 'describes' THEN display 'Description'
100 IF column type is date and user type is government THEN display  
format is 'yyyy-mmm-dd'

> Once you've done that, how do you insert a new rule into the chain  
> at the correct point?  All of these questions are answerable, but  
> they are not trivial.

It seems trivial to put a priority level on the rules, search from  
high to low, and when the first match is made that answers the  
questions needing answering, you're done searching; but I am looking  
at it through different eyes.

> If you want to get a taste of RBP, you might try playing around  
> with the CLIPS expert system a bit... http://www.pst.com/clpbro.htm
> Do a couple toy projects in it and then see if you still have the  
> same enthusiasm for RBP.  If so, then by all means go ahead and  
> write the necessary Engines/Models/Controllers for Catalyst...I  
> think it would be a useful addition to the Catalyst menagerie.  But  
> make sure you know what you're getting into, first.

Will do. Thank you again.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20050606/1ba74c3c/attachment.html

More information about the Catalyst mailing list