[Resolved] Custom Functions and their location(s)

My custom functions tend to grow and grow, as time passes. Which worries me, since I prefer to keep anything that’s custom in the same location.

So, here’s what I’m wondering, when it comes to custom functions.

Do I…

  • 1. define my functions in an external module (that I call in the main.lua), or

  • 2. define all my custom functions directly inside the main.lua?

I expect both work, but I’m looking for a “best-practices” method.

I also ask this to better understand if memory management plays a role here.
If a .lua file gets called, and needs to utilize a function that only one other uses, do I define that function inside the .lua file?

The reason I even thought to ask was from the TabBars Sample code.
On the bottom of each screen.lua file is a function to remove the object and it’s children.
Since I notice it in the bottom of each screen, makes me wonder if duplicating code is possibly teaching a bad practice.

Looking for some thoughts on that.

thanks!

[import]uid: 154122 topic_id: 28170 reply_id: 328170[/import]

I believe both should be more of less equally efficient in terms of memory usage if you are using the “new” way of modularization and not module (…, package.seeall) - we have a few blog posts on that kind of thing and how it relates to memory.

Peach :slight_smile: [import]uid: 52491 topic_id: 28170 reply_id: 113788[/import]

That’s what I thought.
I was originally using the module(…,package.seeall), and now I’m simply placing the functions inside my customfunctions.lua file, while placing: require(“customfunctions”) in the top of my main.lua.

Thanks Peach!

[import]uid: 154122 topic_id: 28170 reply_id: 113793[/import]