[Tutor] Re: small program in Python and in C++

Ashish asis@graffiti.net
Thu, 04 Jul 2002 10:52:38 +0545


I agree that it is easier to declare variables at the time you need 
them. You know what you are using it for. If your functions are so long 
then may be you need to refactor.

Unless it is a class or instance variable, most local variables have a 
scope of few lines anyway. Also I prefer not to reuse my local 
variables. Like c to store the character at one point and some lines 
down when I don't need c to reuse it to store column number. I don't 
think it as great programming and saving memory. I just think it is a 
potential debugging nightmare.

Another advantage of declaring the variable just before using them is 
that it is easier to ensure they are properly initialised.

The only time I declared variables ahead was when I did C and I haven't 
done plain C for 2 years now.

Ashish