Quantcast

Seeking recommendations / suggestions for use of library stacks.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode

I'm starting to make more use of library stacks (partly because I'm
trying to switch away from revIgniter to a CGI-based solution to allow
me to do more work & debugging in the IDE).

And now I'm looking for best-practice and/or suggestions for how to use
library stacks. The not-quite-obvious context is that if some other
library is later put into use, and it has no librarystack handler, then
the librarystack message can get through to my (already in use) library.

My naive approach (from non-LC background) was very simple :

all initialisation would be done in the librarystack handler

that handler would also set a script-local variable to avoid repeated
initialisation

so something like

local sIHaveBeenInitialized
on librarystack
   if sIHaveBeenInitialized is empty then
     put the millisecs into sIHaveBeenInitialized
   else
      -- setup initial / default values, etc.
      ....
   end if
end librarystack

This is fine for subsequent usage of the library - however, it's not so
convenient while working on the library. The problem then is that any
changes made to the initialization won't take effect unless I either
manually unset this script-local, or exit / re-enter the IDE.

I thought about adding a reset handler, e.g.

on library_reset
    put empty int sIHaveBeenInitialized
    pass library_reset
end library_reset

which would give me a quick, safe and easy way to reset any (all)
libraries from the message box. But then I thought it felt like I was
rediscovering a wheel - so I thought I'd ask on here :-)

Is there another easier / better way to handle this ?

Thanks
Alex.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode
On 5/13/17 6:29 PM, Alex Tweedly via use-livecode wrote:

>
> all initialisation would be done in the librarystack handler
>
> that handler would also set a script-local variable to avoid repeated
> initialisation
>
> so something like
>
> local sIHaveBeenInitialized
> on librarystack
>   if sIHaveBeenInitialized is empty then
>     put the millisecs into sIHaveBeenInitialized
>   else
>      -- setup initial / default values, etc.
>      ....
>   end if
> end librarystack
>
> This is fine for subsequent usage of the library - however, it's not so
> convenient while working on the library. The problem then is that any
> changes made to the initialization won't take effect unless I either
> manually unset this script-local, or exit / re-enter the IDE.
>
> I thought about adding a reset handler, e.g.
>
> on library_reset
>    put empty int sIHaveBeenInitialized
>    pass library_reset
> end library_reset
>
> which would give me a quick, safe and easy way to reset any (all)
> libraries from the message box. But then I thought it felt like I was
> rediscovering a wheel - so I thought I'd ask on here :-)
>
> Is there another easier / better way to handle this ?

That's often what I do too. Calling a reset handler from the message box
is pretty simple.

Or if the logic allows it, sometimes I add a check for the environment
to the initialization handler. If the environment is "development" then
I re-initialize.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode
One simple way to make this slightly nicer would be to make sure all your
initialisation happens in a separate handler eg (doLibraryInitialization),
and use your script local lock in the libraryStack handler

> local sIHaveBeenInitialized
> on librarystack
>   if sIHaveBeenInitialized is empty then
>     put the millisecs into sIHaveBeenInitialized
>   else
>     doLibraryInitialization
>   end if
> end librarystack

Then you don't need a separate library_reset handler, just call
 doLibraryInitialization from the message box. Of course you still might
want to flip it from public to private once you deploy.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode
Thanks Ali, that's a nice idea.


But just in case anyone else does the same as me (i.e. copy/paste it
without looking too hard :-) :

there should NOT be an 'else' clause in there .... right now it will
either set the variable OR do the initialization, when in fact it should
do BOTH or NEITHER; i.e. it should be

> local sIHaveBeenInitialized
> on librarystack
>    if sIHaveBeenInitialized is empty then
>      put the millisecs into sIHaveBeenInitialized
>      doLibraryInitialization
>    end if
> end librarystack

On 15/05/2017 09:40, Ali Lloyd via use-livecode wrote:

> One simple way to make this slightly nicer would be to make sure all your
> initialisation happens in a separate handler eg (doLibraryInitialization),
> and use your script local lock in the libraryStack handler
>
>> local sIHaveBeenInitialized
>> on librarystack
>>    if sIHaveBeenInitialized is empty then
>>      put the millisecs into sIHaveBeenInitialized
>>    else
>>      doLibraryInitialization
>>    end if
>> end librarystack
> Then you don't need a separate library_reset handler, just call
>   doLibraryInitialization from the message box. Of course you still might
> want to flip it from public to private once you deploy.
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

pink
what about putting the process into the library stack files themselves?

For example, when I use my CouchDB library I also load fastJSON:

on libraryStack
     if "couchDBLib" is not among the lines stacksInUse then start using stack "couchDBLib"
     if "fastJSONlib" is not among the lines stacksInUse then start using stack "fastJSONlib"
end libraryStack

on releaseStack
     if "couchDBLib" is among the lines stacksInUse then stop using stack "couchDBLib"
     if "fastJSONlib" is among the lines stacksInUse then stop using stack "fastJSONlib"
end releaseStack

note that using "is among" and "is not among" is not optional otherwise you end up in an infinite loop
---
Greg (pink) Miller
mad, pink and dangerous to code
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode
I usually follow Alis approach. I have a separate initialization handler
which I can call repeatedly if needed. The librarystack call just call it
once but if needed I can call it from the messagebox as well.

On the topic of libraries, it is good to follow a "functional programming"
approach where you try not to rely on script local and global variables. If
you library functions need nothing but their own parameters to work on, it
becomes easier to test them and calling them over and over seldon generate
side effects. It is way easier to test (and debug) a function that doesn't
touch anything outside of its own script (as in it processes data and
return data but doesn't cause changes outside itself).



On Tue, May 16, 2017 at 8:34 AM, pink via use-livecode <
[hidden email]> wrote:

> what about putting the process into the library stack files themselves?
>
> For example, when I use my CouchDB library I also load fastJSON:
>
> on libraryStack
>      if "couchDBLib" is not among the lines stacksInUse then start using
> stack "couchDBLib"
>      if "fastJSONlib" is not among the lines stacksInUse then start using
> stack "fastJSONlib"
> end libraryStack
>
> on releaseStack
>      if "couchDBLib" is among the lines stacksInUse then stop using stack
> "couchDBLib"
>      if "fastJSONlib" is among the lines stacksInUse then stop using stack
> "fastJSONlib"
> end releaseStack
>
> note that using "is among" and "is not among" is not optional otherwise you
> end up in an infinite loop
>
>
>
> -----
> ---
> Greg (pink) Miller
> mad, pink and dangerous to code
> --
> View this message in context: http://runtime-revolution.
> 278305.n4.nabble.com/Seeking-recommendations-suggestions-
> for-use-of-library-stacks-tp4714836p4714910.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



--
http://www.andregarzia.com -- All We Do Is Code.
http://fon.nu -- minimalist url shortening service.
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Seeking recommendations / suggestions for use of library stacks.

Richmond Mathewson via use-livecode
I would agree, but I have become fond of constants, especially in objects where code is similar but need certain things to be different. For instance I have a button bar which opens for edit, creates new form, deletes data, saves data etc. I copy this bar to each of my forms. The code in most buttons is identical, but the tables and validations, as well as parameters passed to library functions changes for each form. In this case it becomes useful to me because to make the bar usable by any of my forms, I only have to edit the constants of each button.

Bob S


> On May 18, 2017, at 19:33 , Andre Garzia via use-livecode <[hidden email]> wrote:
>
> I usually follow Alis approach. I have a separate initialization handler
> which I can call repeatedly if needed. The librarystack call just call it
> once but if needed I can call it from the messagebox as well.
>
> On the topic of libraries, it is good to follow a "functional programming"
> approach where you try not to rely on script local and global variables. If
> you library functions need nothing but their own parameters to work on, it
> becomes easier to test them and calling them over and over seldon generate
> side effects. It is way easier to test (and debug) a function that doesn't
> touch anything outside of its own script (as in it processes data and
> return data but doesn't cause changes outside itself).


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...