local or not functions

I feel like this is a really silly question, but I can’t seem to grasp the answer to the scope.

I understand the difference between global and local variables, and when they need to be local and not. But when should a function be declared as local and when should it not?

Frankly speaking, the only advantage to globals is convenience.  There are much better ways to handle your functions that avoids globals.  It takes a touch more work.

This tutorial shows you how to setup a module that you can attach your functions too that keeps them out of global space yet makes them available across modules.

http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Ahh, thanks Rob. I’ve read that post before and actually make use of a data holding module. I guess I never thought of functions as the same as variables in this respect! Now I feel silly.

No need to fill silly for “Eureka!” moments!

Frankly speaking, the only advantage to globals is convenience.  There are much better ways to handle your functions that avoids globals.  It takes a touch more work.

This tutorial shows you how to setup a module that you can attach your functions too that keeps them out of global space yet makes them available across modules.

http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Ahh, thanks Rob. I’ve read that post before and actually make use of a data holding module. I guess I never thought of functions as the same as variables in this respect! Now I feel silly.

No need to fill silly for “Eureka!” moments!