Santiago Pericas-Geertsen wrote:

Chris, I think all your points are valid from a software engineering
standpoint. I also agree that the use of final does not buy much in terms of
performance, but sometimes a minor improvement is welcome too (akin to not
adding "virtual" if not needed in C++). Besides, I don't think it is hard to
"definalize" things.

I disagree. It may be easy for you to "definalize" your own code, but when someone else would like to use your code in their own work, they get stung by the fact something is final and they can't do what they want, and they end up creating their own copy of the code and maintaining it just to get rid of the final keyword. Remember, your code is not always going to be the "final" implementation, *especially* if you do a good object oriented design.
I think if you are going to break the rules like this, you should do an actual test (no assumptions), and document your results in the source code with a statement of why you think this is good. This way someone else looking at the code can see your reasons, and may decide at some point that it is no longer justified. You might learn in the process that your assumptions were wrong, and if nothing else it gives you some confidence that you are making the right decision. If it comes down to saving a couple of milliseconds during an operation that takes a minute to execute, it becomes a lot harder to justify.


Other good examples of questionable performance enhancements include object pools like String pools or memory pools.


This is why String and the primitive objects
such as Integer and Double are declared final. Otherwise you could
simply subclass the object and do what you want, which would mean that
you would have to make a copy of every String that you wanted to hold on


to.

I agree with your comments, except for the one above. What do you mean "do
what you want"? Instance variables in those classes are private.


I think Joseph already answered this, but here is a concrete example:

public class MutableString extends String  {
  public MutableString(String value)  { mutableValue = value; }
  public String toString()  { return mutableValue; }
  public void setValue(String value)  { mutableValue = value; }
  private String mutableValue;
};


-- Chris P. McCabe - Principal Engineer Choice Hotels International - Information Systems [EMAIL PROTECTED] 602-953-4416







Reply via email to