Is this a bad practice?

I want to organize my framework. So, I put all the modules and folders I need into tables like this:

local Folders = {
    Folder1 = ReplicatedStorage.Folder1
}

local Modules = {
    Module1 = require(Folders.Folder1.Module1)
}

I just want to make sure this isnt bad for performance due to memory leaks. Thanks!

2 Likes

This is a dictionary not a table. I’m not sure how this would be a reason for memory leaks? A memory leak is caused from losing a reference to something without cleaning it up like a connection(disconnect exist for a reason). Having a refence to something that is no longer needed can also be a memory leak due to it not being garbage collected.

Fine then. But did you read the title? You replied but didn’t answer the post’s key question.

It’s not bad practice to have access to all the modules in 1 script because it’s easy for communication reasons.

Although you could manage them easier and require them via a loop so you don’t have to manually type them all in every time.

I think throwing folders into dictionary is a little redundant though… modules could be useful in a dictionary for referencing purpose. Most frameworks use 1 script with many modules.

That’s what the Crystal Framework does. One client script, and one server script.

1 Like

So you’re saying, that something like this would be better so I could add easily without editing every script?

function g:ReturnServer(): {ModuleScript}
	local modules = {}
	for _,module in ipairs(ServerStorage.Modules) do
		table.insert(modules, module)
	end
	return modules
end

This is not bad practice, and this should be moved to a personal module script so you can access these variables from other scripts without having to define them from other scripts.