local forward declarations when using composer or storyboard scenes

Q. Is it a good practice to declare all function and variable names as local in the forward declaration section  of a storyboard or composer scene? The reason i’m asking this is i’ve come across errors like “attempt to index some function_or_variable (a nil value)”. These errors are usually scope related errors. What i’d like to know if the coding style below is good practice to avoid such errors?

-- forward declaration section -- variable names local mesg, ctr, initValue,finalValue,score,num\_of\_coins... -- function names local postMesg,checkCoins,buyCoins..... -- forward declaration section ends function checkCoins() -- code end function buyCoins() -- code end function postMesg() -- code end

i tried searching on Corona Labs Forums and came across two similar questions but with no answers -http://forums.coronalabs.com/topic/40072-question-on-best-practices-for-storyboard/?hl=%2Bstoryboard+%2Bbest+%2Bpractices

Can you share your best practices for usage of variable and function names  in Corona Storyboard or Composer API’s , many thanks in advance!

fwiw, my preference: adopt OOP, make everything a member of “scene”, and all your forward declare worries vanish automatically. the only time i want to see “local” at module scope is for require (and, of course, once for the class/scene itself).

you gotta go all the way for it to really work tho, as you’re implying a lot of disparate functionality in your scene. i’d rather see separate classes for store operations, social media posting, holding user data (score), etc - those then become local requires.

caveat is: i’ve been using Lua for 15+ years (since 3.0, long before Corona) so that approach might not be suitable/practical for entire audience here.

i’d probably run screaming if approached with contract to polish “local msg, ctr” -type code! :smiley:

thanks for your reply Dave! i’m just getting started with Corona and liked your suggestion about creating separate classes and then using them via local requires  :). That takes care of common functionality across various modules. As for the OOP approach i’ll give it a try though i’m not too versed with how it works in Corona. Will post updates on how it goes, thanks for sharing your best practices!

fwiw, my preference: adopt OOP, make everything a member of “scene”, and all your forward declare worries vanish automatically. the only time i want to see “local” at module scope is for require (and, of course, once for the class/scene itself).

you gotta go all the way for it to really work tho, as you’re implying a lot of disparate functionality in your scene. i’d rather see separate classes for store operations, social media posting, holding user data (score), etc - those then become local requires.

caveat is: i’ve been using Lua for 15+ years (since 3.0, long before Corona) so that approach might not be suitable/practical for entire audience here.

i’d probably run screaming if approached with contract to polish “local msg, ctr” -type code! :smiley:

thanks for your reply Dave! i’m just getting started with Corona and liked your suggestion about creating separate classes and then using them via local requires  :). That takes care of common functionality across various modules. As for the OOP approach i’ll give it a try though i’m not too versed with how it works in Corona. Will post updates on how it goes, thanks for sharing your best practices!