Saturday, October 04, 2003

Directories are Java source file package names

After reading this blog by Gregg Wonderly and some of the comments posted at the blog I decided to write this blog entry.
For a long time I used to think directories are not Java source file package names because Chapter 7 of Java language specification said so. Also many a times(For any product that you work on for long time) maintaining directories as Java source file package names is a pain. Imagine you are developing a product called javamagic. You are working for a oraganization which has several suborganizations and with several products for each sub organization. If your java source files must be in a directory tree mirroring the package name, your source directory would typically look something like this:

Having this structure is pain and sounds dumb because you know com/javaswamy/jone/javamagic is always constant and there is absolutely no need to maintian this filesystem hierarchy as you know what you are working on. If possible a simple hierarchy like this would be what everyone likes to have:

This is easy to navigate and presents developer view of the code.

Now lets get back to reality. Though Java Language Specification doesn't impose the restiction of Directories are Java source file package names, JavaDoc does. JavaDoc tool faq states "If your classes do not all belong to the unnamed package, you must put them in directories named after the packages.". So if you need to generate javadocs for your project and use JavaDoc tool to generate the documentation, Directories are Java source file package names.

Like many other java programmers, I would love to see JavaDoc team solve these problems that exist since JDK1.1 days:
1. Directories are Java source file package names.
2. Deprecation warning is suppressed if the compilation unit containing the deprecation is being compiled at the same time as the compilation unit using the deprecated class or member.

No comments: