> its also horrible programming practice to do it the way you have.
> its best to declare all the variables you need at the top, and,
> give them values below. in rare cases,

I don't think it is a *horrible* programming practice to declare your
variables where you use them (assuming you are using C++ ofcourse).

If I had a function that was 150 lines long, and I need a local variable
near the end, why would I declare it at the top of the function (or block)?
That would require the programmer that comes in after me to remember how the
variable was declared at the top of the block, and if he forgot, he would
have to scroll back up to see how it was declared.  One other point is that
it keeps another programmer from coming in and using the variable assuming
that it is already setup correctly.  For example.

void test( void )
{
    // Non meaningfule value, just an initiailizer.
    int a = 0;

    <begin lots of lines of code>
        // Maintnance programmer inserts line here.
        a += 20;  // Wants 120, but gets 20.
    <end lots of lines of code >

    // Intial meaningful value
    a = 100;
}

The code snippet is meaningless in itself, but the scenario can happen
happen.  If *a* were declared where it was used, the compiler would throw
out an error long before a bug was introduced.

So is it so horrible?

Brad



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to