The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Just another thought

Posted by Kishori Sharan on January 23, 2001 at 11:10 AM

Hi
Look at the following code:
if ( balance > 100 ) {
// Do some processing here
}
else {
// Do nothing
}
In above code one programmer says that else part is not necessary ( rather it is redundant ) beacuse we don't do any thing in "else" part. So remove it. Another programmer says, it is a good programming practice to include an "else" part for every "if" even if you don't do anything in else part. Second, programmer's argument is that you should have "else" part just to make a point that you were aware of the else conditions that might occur while you were writing this piece of code, however it is true that you don't want to do anything in "else" part.
Your query about setting objects to null is like this. However, in some cases when you are doing some memory intensive processing in a method then it is really good idea to set even local reference variables to null after you are done with it. Suppose, you are in a method which has 200 lines of code and at line 50th some local reference variables are no more needed. You may need some memory which GC can make you available if you set your local variables at 50th line to null, else when you need more memory while executing the same method you may get outofmemory error.
So you can make a rule that create an object only at the point you need it first time and set its reference to null when you are done. But, setting object refernce to null should not be enforced stricly in all cases.

Thanx
Kishori




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us