Does it prevent problems to define a variable before it is re-defined in all possible branches of a conditional?
For instance should this code:
# Condition could fail
try:
textureIndices = someExpression()
# textureIndices is defined here if it does
except:
textureIndices = []
return textureIndices
Be re-written as this:
# textureIndices is defined early and then re-defined in the conditional
textureIndices = None
try:
textureIndices = someExpression()
except:
textureIndices = 66
return textureIndices
Or, because except opens other issues, is there a problem with the definition of textureIndices here:
if condition:
textureIndices = someExpression()
else:
textureIndices = 66
return textureIndices
to reduce problems?
The only difference is in the second version textureIndices is defined outside of the conditional.
I do not see why it matters because it is impossible for textureIndices to not be assigned a value in the conditional but I can see why from a housekeeping perspective it is nice to know the variable is assigned to something.
For instance if there was no except statement in the first example, then textureIndices wouldn't always be defined and return would cause an error.
However, are there problems if one does not forward define variables that are defined in both causes of a conditional?