Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Coding conventions for AspectJ

I prefer explicit imports because they make the code more readable.
I believe JBoss code conventions require explicit imports.

However, explicitness is a pain to manage when coding, even
with Eclipse's add-import command.  So to encourage those who
contribute, I would go for your convention (do package imports 
for >2 types) and add that we should order imports according 
to eclipse defaults (assuming these track 
org.eclipse.jdt.core/src/**/*.java).

Considerations follow, if discussion is warranted...

Wes

---- explicit imports - clearer but harder to use
- need to "add import" for each new type used 
  before code-completion works.  
  (Can use package imports until code is checked in.)

- need to run "organize imports" when pruning types
  to avoid "unused import" warnings

- difficult to manage outside eclipse

---- wildcard/package imports - easier to use
- only need to "add import" for each new type 
  used from a package not imported

- confusing: need to hover or navigate to find actual type;
  might accidentally use a type from one imported package 
  thinking it is a type from another package not imported.
  When organizing imports to disambiguate type names, no
  prior reference to select from.

- might be harder to compile -- scanning all packages...

---- open-source considerations
- For org.eclipse.jdt.core sources, we'd like to match their
  conventions to avoid merging import statements where possible.
  The workaround is to manage imports manually in this code base;
  I'm not sure how much change we're anticipating from now on.

- By extending/adapting JDT and BCEL and using a lot of structural
  or general types (ASTObject...), we have a high population
  of ambiguous unqualified type names.  These (to me) are easier
  to understand/manage with explicit imports.

- Explicit imports make code more readable, which might encourage
  open-source contributions, but they also make it harder 
  to contribute.  We can probably rely on contributors using
  Eclipse to mitigate either case.


Jim.Hugunin@xxxxxxxx wrote:
> 
> I hate to spend time on trivia like this, but I've recently been reminded that coding conventions are extremely important when multiple developers work on the same code base.
> 
> The basic coding conventions for this project are simple.  We follow the eclipse coding conventions (which are essentially the SUN coding conventions) found at http://dev.eclipse.org/coding.html
> 
> However, there is (at least) one issue that isn't specified there that we need to agree on.  That is when to use "import java.util.*;" vs. "import java.util.List;".
> 
> I propose the following rule.  Use the '*' form whenever you would have more than 2 non-star imports from the same package.  When programming in eclipse, this means that in Organize Imports everyone should set the number of imports before '.*' is used to 2.
> 
> My opinion is that this offers a compromise between being able to easily see the exact 1 or 2 classes used from a particular package and reducing the excessive verbosity that occurs when 10-20 classes are used from a single package.
> 
> I think that a discussion of the exact value of this number would be a waste of time.  However, I expect that some people might be attached to the eclipse default value of 99 (or essentially infinity) and I'd like to give them a chance to weigh in on what the AspectJ policy should be.
> 
> -Jim
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-dev


Back to the top