« Wiki asshole on the... | Main | JSP-based tree contr... »

Software is never perfect.

James Robertson of the Cincom Smalltalk blog picked up on my post about the final keyword and one of his readers, Blaine Buxton, made an interesting comment on the topic. Software is never perfect, as Blaine says, and I agree, but if you allow your users to customize your software by extending classes and overriding methods, you can get yourself into trouble very quickly. When you deliver a new version of your software to them, you might find that you have broken many of their customizations and enhancements. It takes some thought to write a class that is truly safe for users to extend. An typical object is like a state machine and by calling methods in the wrong order or incorrectly overriding a method, your users can easily put that state machine in a bad state. Open source helps, of course, because users of an open source application or class library can see the internals of the classes and, one hopes, understand how to correctly extend them.

I'm not saying you should never allow users of your class libraries or applications to extend your classes and override your methods, but I think, in general, it is better to provide them with extension points in the form of interfaces that they can implement to extend and customize the behaviour of your library.

Blaine Buxton In this context, it would be more natural thought for a Schemer/Functional programmer. Functional languages frown upon mutable variables because they make "proving the correctness of the code" more difficult. They see variables as you would in mathematics, they never change. Personnally, I forbid the use of final on methods in any projects that I have anything to do with because of the exact problem you explained. Software is never perfect. But, I do advocate using final on variables for constants and that's it. I think trying to turn Java into a functional language (in the sense of Scheme and Haskell) is like trying to make pigs fly. Now, just don't even get me started on the use of the private keyword on methods! My hatred for it is the same as final on methods and you should NEVER do it.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

« Wiki asshole on the... | Main | JSP-based tree contr... »

Welcome

This is just one entry in the weblog Blogging Roller. You may want to visit the main page of the weblog

Related entries

Below are the most recent entries in the category Java, some may be related to this entry.