I think it's better to define variables when they are used rather than at the start of the function, but this is of course still an improvement over accidentally using global variables.