geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Strachan <james_strac...@yahoo.co.uk>
Subject Re: Coding standards: import thing.* or thing.Class?
Date Wed, 13 Aug 2003 17:29:29 GMT
On Wednesday, August 13, 2003, at 06:22  pm, Noel J. Bergman wrote:
> Alex Blewitt wrote:
>> Has anyone got any preferences between using:
>>
>> import java.util.*
>>
>> or
>>
>> import java.util.Vector
>> import java.util.Enumeration
>
> Personally, in most cases I find that the actual pattern is something 
> like:
>
>   import java.util.Collection;
>
>   Collection mywhatever;
>
>   mywhatever = new java.util.SOME_COLLECTION_TYPE(...);
>
> I do not bother to import the specialized class used only once.  I do 
> import
> the base type that is part of the interface.

There's always one :). Seriously, it just shows how subjective coding 
styles are really.

FWIW I prefer to have all imports at the top of the file, expanded and 
then never to use fully qualified class names in the actual code so that

* folks can see exactly what the dependencies of a class are by just 
looking at the imports rather than trailing through the whole code 
(this can help show some bad package hierarchies etc).

* folks that aren't interested in dependencies can skip the imports 
(most IDEs go straight to the meat of the class anyways)

* the actual code you write (the stuff you spend more time reading) is 
simpler and shorter due to lack of fully qualified class names

The only exceptions to this rule are when you get class names clashing 
- but typically thats a code smell which you can fix by refactoring.


The beauty of coding standards is we've so many to choose from... :)

James
-------
http://radio.weblogs.com/0112098/


Mime
View raw message