local function ABTest(A, B)
local A = A
local B = B
print(A, B)
end
I really don’t see the difference in either, though I have seen developers and their code opt to use the latter over the former. Is there some kind of performance or functional difference that I’m unaware of, or is this a matter of preference?
I notice that in a similar but different context, developers also assign methods of standard libraries into upvalues at the top of their scripts. Such an example is as shown below:
local MATH_ABS = math.abs
local MATH_CLAMP = math.clamp
local CFrame_new = CFrame.new
local function ABTest(A, B)
local A = A
local B = B
print(A, B)
end
…are the exact same. There is no optimization and any developer using the latter most likely does not understand that. Use the former since it’s more readable.
It’s a micro-optimization that saves microseconds, not enough to worry about. Avoid it if it makes the code less readable.
Anyways the reason why I did that was because it’s used very often such as in a function binded to RenderStepped used for visual effects, it’s called about 60 per second and I want it to be as fast, efficient and smooth as possible, but you can use it for other situations too, this does improve efficiency but don’t over do it.