Style question (was Re: Test)
Frank Morton
fmorton@mail.base2inc.com
Wed Sep 16 12:19:00 GMT 1998
>No, because no-one has posted questions or asked discussions.
>Do you have a question or discussion topic to get the list
>rolling?
>
> --Per Bothner
>Cygnus Solutions bothner@cygnus.com http://www.cygnus.com/~bothner
I will because I'd like to have a place to ask general questions.
You know the old rule of don't do anything inside a loop repeatedly
that can be done once outside the loop. Say you are going to somehow
manipulate a String by looking at each character. The code is cleaner
doing the following:
for(int k=0;k<thestring.length();++k) {
char c = thestring.charAt(k);
// do something to it
}
This is how I have been doing things for a couple years now, but I always
wonder what kind of performance hit I am taking by not moving the
"char c" declaration outside the loop and breaking the age old rule.
Or does the optimizer take care of it?
What do you all think? What do you do?
More information about the Java
mailing list