From: Jonathan C. <cra...@pc...> - 2003-08-02 19:28:17
|
Steve- By the way, there are certainly others who believe import .* is bad. See, for example, this page (from someone who has written a utility to expand import statements): <http://javadude.com/tools/importifier/> This person makes the statement that "Import on demand is pure, unadulterated EVIL." and then gives three arguments to back it up: > * If you use a name that exists in more than one package, the Java >compiler cannot determine which fully-qualified name to use. You need to >specify the full qualification yourself. True, but that's OK so long as the total time you spend doing this is less than the time you save by using import .* in the first place. Plus, in most cases the programmer will be aware of ambiguous class names and will avoid using .* in those cases. > * If a name is currently unambiguous (exists in only one package that >you specify via import-on-demand), someone could add the same name to >another package and your program will no longer compile. This is a very good point. However, costs are incurred whenever code on which you depend is changed. For example, if that same person had instead changed the definition of an interface or renamed an existing, your code would also not compile. That's just life. > o Note that this happened with the Java2 platform. Originally, >the List class existed in package java.awt. In Java2, Sun added a new >List class to the java.util package. If your program imports java.awt.* and >java.util.*, and uses List, it will compile in JDK 1.1 but not in the >Java 2 platform! This is the same as the previous argument, and although I agree it's a terrible "feature" from a theoretical standpoint, in practice it's just not that big a deal. I certainly agree that production/released code should use fully-qualified imports, but while it's under development I think a certain amount of laziness is a good thing. > * If someone is reading your code, they need to check in each >specified package to see which contains a referenced class Foo. Or, they could do one of the following things: 1. Run the code through a program that will do it for them. 2. Use etags or JDE or a similar feature to look up class names. 3. Read the JavaDocs for your program before looking at the code. Jonathan |