Hello hello everybody :D!! recently i wanted to give a shot at creating my own maid module since my oop skills have improved a lot since last year. Today im here to announce that its finally done . Its completley free to use. You dont have to credit me or anything. All i ask is that you tell me if you find any bugs or anything that you think could be improved. All feedback is appreciated and helps out a lot (: !!
Heres the instructions on how to use it(Theyre also inside the module)
Should also point it out before someone does. I didnt know what to call the thing Maid:GiveTask() returns(Object). I was going to name it Class but im not sure if thats the right word for it.
You might want to call it something other than Maid to avoid confusion. For example, alternatives to the Maid module call themselves Janitor and Dumpster.
Sorry for the confusion. I meant that usually modules that are open sourced have unique names so there isnāt confusion between them. Just a suggestion though, it really isnāt that important. For personal projects you should just name things whatever is most convenient to you as @Tomarty mentioned.
Some example names might be cleaner, bin, can, trash, trunk, etc.
Class is the right word for that. A class is something like Maid (uppercase). Not to be confused with an instance of a class, which is something like Maid.new(). (Another example, in the code local newMaid = Maid.new(), newMaid is an instance of the class Maid.)
I see no reason to use anything else. Maid is a great name thatās simple and ergonomic. For my project I somehow ended up calling mine āCnsā (short for āconnectionsā.) Iāve considered renaming it to āMaidā but it hasnāt been a problem for my codebase. I type it thousands of times and it works.
At first I didnāt really use a class for it:
-- Create
local cns = {}
-- Add things that need to be cleaned
table.insert(cns, function()
part:Destroy()
connection:Disconnect()
-- etc.
end)
-- Clean it up
for i = #cns, 1, -1 do
cns[i]()
end
I have a pretty involved compile process for my project that can do tokenization and inter-module constant-folding/function-inlining, so now I use static methods:
-- '_R' is just part of my module loader defined at the top with dependencies.
-- Create.
local cns = _R.Cns.new(1) -- '1' is the preallocation amount. It compiles to use table.create.
-- Add things that need to be cleaned. This simplifies to table.insert.
_R.Cns.Add(cns, function()
part:Destroy()
connection:Disconnect()
-- etc.
end)
-- Prevent adding new things by accident.
_R.Cns.Lock(cns)
-- Unlock when used with Lock, is useful for locking an object while creating a new one. I often have deeply nested connections and this prevents 99% of scope-related problems.
_R.Cns.Unlock(cns)
-- Clean it up. This simplifies to the same code as the other example.
_R.Cns.Call(cns)