Putting common functions in code modules

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
bergsy
Posts: 45
Joined: Mon Oct 28, 2013 10:51 pm

Putting common functions in code modules

Post by bergsy » Thu Sep 17, 2015 5:28 am

Hi,

I am at the stage where I need to modularise my mainstack. There are bunch of common routines that I need to be able to call from any substack/object. To date I have just put them in the main stack and they become accessible. However my main stack is becoming very large (over 10k lines) and I want to take related routines out into their own code modules, yet still have them available to all substacks and objects.

Not sure how I do this in Livecode.....

Greg

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Putting common functions in code modules

Post by SparkOut » Thu Sep 17, 2015 7:06 am

How you structure your stack/s is a matter for you, but 10k lines is not something to make LiveCode shudder.
For clarity and ease of maintenance, and portability of libraries, it is simple to put all your library handlers into a substack. Then you can issue the statement:
start using stack "myLibrary"
Then all the handlers of the substack will be available. Thus it is simple to store your libraries in stacks of their own, and attach them to a new project.
But there may be other ways that suit you (or other coders - who may have more ideas) better.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Putting common functions in code modules

Post by dunbarx » Thu Sep 17, 2015 1:54 pm

Hi.

The question to ask is why it is better to put your library code in another stack. Is it for easier access to them, or are you concerned that the list of handlers, or their length, has made the stack script difficult to work with?

I never use two stacks when one will do. Even if the list of handlers in the stack script grows quite large, it would do so also in the library stack, and then what would that accomplish?

Craig Newman

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Putting common functions in code modules

Post by SparkOut » Sat Sep 19, 2015 9:33 am

I think Greg is concerned with code maintenance and clarity. With one stack script, in the debugger it can be daunting to find a handler and see the other handlers which are relevant to it. If all the database code is in one substack script, and all the ui code is in another substack for instance, it can help with your own thought processes. Wouldn't it be a good idea to be able to put section markers in the script and be able to see the different sections (of the same script) in a separate tab?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Putting common functions in code modules

Post by dunbarx » Sat Sep 19, 2015 2:54 pm

Sparkout.
Wouldn't it be a good idea to be able to put section markers in the script and be able to see the different sections (of the same script) in a separate tab?
That sounds as cool as the ability to add annotations to lines of code like a toolTip. I have wanted that forever. To be able to write a paragraph, if you wanted to, and read it by hovering over a single line of interest.

Craig

Post Reply