The first, as far as I know, I believe using parentheses gives some operator precedence, but I don’t know for sure, so don’t quote me. Someone please confirm this.
But it does make code look cleaner when your doing multiple checks in an if statemenr.
The second, both statements are equivalent.
if not debounce then
— code
end
if debounce then
return
end
Are just two different ways of doing the same thing, there’s really no difference between them.
You seem to be referring to a guard clause though in an incorrect usage. return is used to stop the function from continuing which a guard clause uses, it is mainly for readability.
I say incorrect since using return at the end of function isn’t really a guard clause because its at the end of the function which using return has no difference versus no return there.
It prevents nested code mainly
if condition then
-- example
if condition2 then
-- stuff
if condition3 or condition4 then
-- stuff
end
else
-- stuff
end
else
-- stuff
end
Becoming this instead:
if condition then
-- do stuff
return
end
if not condition then
-- do stuff
return
end
if condition2 and (condition3 or condition4) then
-- do stuff
return
end
if not condition2 then
-- do stuff
end
There’s zero difference in the result, they will do the same thing. The difference is visually reading that code.