Nesting Functions A Bad Idea For Optimization?

Hello there,

I was wondering if nesting functions within one another is a bad idea, especially optimization-wise. 

Example of what I mean :

local function step1() local function step2() transition.to(object2, {time = 10000, x = 123, onComplete = step3}) end transition.to(object1, {time = 5000, alpha = 0, onComplete = step2}) end

Basically I’m nesting a lot of functions within one another to group them and I’m wondering if it’s a bad idea and I should just separate them out.

Things to note:

  - I won’t be needing to call these nested functions outside

  - I’ll be calling the function step1 in this example, multiple times throughout the game.

Would appreciate any advice, and I’ve already looked at http://developer.coronalabs.com/content/performance-and-optimization.

Thank you!

What you are doing is a good practice as long as you know you are doing it.  When you put functions inside a function, it conveys to the reader that this is only used here.  But if you don’t know you’re doing it and you later need that function somewhere else, it becomes frustrating to you trying to figure out why it doesn’t work.

So it’s really a trade off based on good organization vs. flexibility.

Rob

What you are doing is a good practice as long as you know you are doing it.  When you put functions inside a function, it conveys to the reader that this is only used here.  But if you don’t know you’re doing it and you later need that function somewhere else, it becomes frustrating to you trying to figure out why it doesn’t work.

So it’s really a trade off based on good organization vs. flexibility.

Rob