Musings on Architect, MVC, Nested Behaviors

Trevor DeVore lists at
Thu Dec 27 00:20:10 EST 2018

On Wed, Dec 26, 2018 at 1:09 PM Sannyasin Brahmanathaswami via use-livecode
<use-livecode at> wrote:

> With that in mind, though you say "Levure doesn't have a strong opinion
> one way or the other. There is no code that is designed specifically around
> the Model-view-controller (MVC)
> pattern." I want to start using you conventions. A few more questions...
> 1) "to separate each stack with UI objects into a separate stack
> file and to use behaviors assigned to the card "
> You keep these in a separate folder, 1 per stack and behavior(s)?

Yes. An app that fully embraces the Levure approach has a `ui` folder which
contains any number of sub-folders. Each sub-folder has a binary stack with
the UI objects and a `behaviors` folder with any behaviors. The wiki has a

> 2) Are behaviors loaded in memory when a user loads the card and
> "unloaded" from RAM when the  users closes card? That question goes to
> performance on libraries (open at start up) versus behaviors. I don't know
> if these texts script will impact performance, relative to a JPEG that you
> bring in, or a deep dbase query... Mark once said that scripts  are not "a
> problem" but more about what they tell the CPU to do and what  UI is doing
> to the pixels on screen - Images etc. But I keep wondering about that.

Behaviors attached to a UI stack will be loaded when the UI stack is
loaded. If you have the `destroyStack` set to true then the stack will be
unloaded when it is closed but the behaviors will not be. Monte recently
told me about the `revbehaviourses` function which can be used to unload
behaviors which are not in use by any other stacks. There is an open issue
to add support for removing behaviors from memory when closing a stack. See

> 3) What do you think of nested behaviors,  where the "uber parent" is a
> model and the child behavior is a view/UI behavior, controller VS just
> keeping that model in libraries that remain open all the time? Goes to #2
> above.

While I've never done it that way (I have defined my model interfaces in
library stacks out of habits established prior to behaviors) there could be
value in that approach. Take a model interface that can have multiple
instances of the model. If you use a library script you have to pass a
model instance identifier to every handler in the library. Using a behavior
script attached to a card could remove that need as each behavior has it's
own instance of the script local variables used in the model behavior
script. The approach could also simplify callbacks because the target would
always be the object the model behavior is attached to.

Nested behaviors can become complicated but your project organization can
make that easier to follow. For example, models can all be stored in a
`models` folder. Or you could store them in a `behaviors/models` folder so
that it was obvious they were used as behaviors. Or in `libraries/models

There are come designs that could be simplified The nice thing about
behaviors is that each instance has it's own script local variable values.
Depending on what your model interface looks like you might be able to do
away with having to pass an "id" to each model handler to uniquely identify
the model associated with a particular view.

> My guess is that, if the code is being reused enough, it's just a text
> file (hardly adds to the RAM) , and debugging--  also "to figure out how
> all of the code works together when you revisit the project or try to add a
> developer" -- that using a library and keeping it in a library folder,
> probably keeps it simple/more easily understood.

More information about the Use-livecode mailing list