View Single Post
  #6 (permalink)  
Old 06-24-2009, 09:57 PM
porchrat porchrat is offline
Member
 
Join Date: Mar 2009
Posts: 41
Rep Power: 0
porchrat is on a distinguished road
Default
Originally Posted by pbrockway2 View Post
> IMO it is always a good idea to initialise your variables in the beginning

Compiler messages are good things and should be embraced.

Assigning values to variables "just in case" is only going to frustrate the compiler in its analysis of your code, and stop you getting helpful messages.

Code:
Foo foo = null; /* null just in case... */
if(someCondition) {
    foo = createFoo();
} else {
    // whoops! forgot to initialise foo in this case
    // This is a logic bug...
}
foo.doStuff(); // ...but the compiler won't pick it up
Good point :P.

Last edited by porchrat; 06-24-2009 at 10:05 PM.
Reply With Quote