The Number One Ill Of Java ...
... is its stupid "directory structure reflecting the package hierarchy" (mis)feature.
I was "helping" 20-year programming veterans to "understand" this (mis)feature in 1998. I'm still "helping" people to understand it now.
"I have a directory full of Java sources right here. Why do I have to tell javac or my IDE that the sources are three directories up?"
There is no good answer to this question. Sure, you can get use to it. You can even be proud that you are among the 5% programmers who persevered in understanding it. But it doesn't make it right!
You can label the on switch "off" and the off switch "on". People will get used to it. But that doesn't make it right.
It causes unnecessary problems. And its another barrier to true understanding.
That, and zero-based array indexing, have got to go.
Re: The Number One Ill Of Java ...
There are many nice tools out there that do help you to manage all your sources and packages. Use Netbeans and you don't have any problems in creating/managing packages.
I think it is very important for all good programmers to understand packages and why and how to use them. It is very easy to write software but it is very hard to write good software...
And for the zero-based arrays: it is intuitive and helpful in many ways. For example does it help you in using modulo for ringbuffers or something like that.
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
the only thing you are saying is that you are not used to, is the same, you have not given any real argument but I am not used to
on the other hand the readers have said interesting stuff for example the feature of the packages, it is a lot easier to read, to search into files, have you tried C#? there have a really (mis) feature that your package can be in any folder and it does not matter, I found it difficult.
The array starting from zero, well I might give you that one, nevertheless I was used to from C and C++ so it was pretty smooth for me, anyhow sometimes you ask yourself should I be using 0 or 1, e.g. resultset.getString(0) or resultset.getString(1), obviously you ought to use 1, that is sort of dumb maybe, ain't standard but hey don't be mad at a language
Re: The Number One Ill Of Java ...
C#, on the otherhand, allows you to declare namespaces in any arbitrary file in and any directory (this is necessary for them to implement the "partial class" functionality). I deal with large sources trees in Java and C#, and I much prefer navigating the Java structure. In C# I usually end up hunting for classes all over the place since I have no idea where to look.
Maybe you haven't dealt with lots of large OO source file structures? The Java structure is a breath of fresh air.
Re: The Number One Ill Of Java ...
Although I have to say I like the partial class feature of .net. The typical use is to add your own functionality to generated classes, which is nice if you do domain driven design. No stunts with inheriting from generated base classes required.
A similar feature for java would be helpful, maybe by compiling sources from multiple source trees (e.g., from src/my/package/TheClass.java and generated/my/package/TheClass.java) into a single class file.
- PatrickRe: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
What IDE are you working with ? Could you detail the steps involved in "tell[ing] [your] IDE that the sources are three directories up?".
I mostly use eclipse and I've never had to tell it more than base source directory. As for opening files, I mainly use the Ctrl+Shift+T and Ctrl+Shift+R shortcuts which prevent you from navigating the whole tree. I suppose other modern IDEs provide similar features.
The same goes for javac. It takes a sourcepath argument that specifies where to find input source files. You give it the base directory and voilà. Again, when and how do you have to "tell javac [...] that the sources are three directories up?"
If people have problems understanding that, learning the rest of Java must really be painful for them.
Well, at least I'm in the upper 5% of something :-)
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
You want a discussion. Let's have a discussion.
Give me one reason why putting the class com.weiqigao.discussion.Topic in com/weiqigao/discussion/Topic.java is better than putting it in just discussion/Topic.java.
"It's better because that's the way it works." doesn't count as a good reason.
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Dude, by posting this you are asking to get flamed. Actually, I take that back. The guy who posted a link to this on TSS, wanted you to get flamed.
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Because Java picked a structure, there are not thousands of different conventions (one for each project out there). This makes it dramatically easier to navigate java source code, regardless of whether you're familiar with it or not. It removes endless arguments about what the structure should be. It lets every Java programmer find sources (and classes) quickly and know that what they are looking at is what they want to look at.
I bet this has saved literally thousands of man-years when measured across just the span of all developers working in Java during it's lifetime so far.
Re: The Number One Ill Of Java ...
But doesn't it violates the Don't Repeat Yourself (DRY) principle?
It also robs the programmer of a valuable tool for source code organization—the directory structure.
It leads to excessive and convoluted directory hierarchies in most Java projects. Most big projects that have the concept of separately compiled "modules" are forced to use another set of directories outside the package-induced directories:
server/
src/
com/
acme/
server/
Server.java
common/
src/
com/
acme/
common/
Common.java
client/
src/
com/
acme/
client/
Client.java
Re: The Number One Ill Of Java ...
With regard to organization, I don't think it eliminates the ability to organize code. Your example demonstrates how to segregate the code. What organizational opportunities in particular do you think are being lost?
Re: The Number One Ill Of Java ...
In my last example, the "/com/acme" portion of the directory structure is arbitrary and excessive and wasteful and irritating and serves no useful purpose what-so-ever, given that every thing in the project falls into the com.acme.* package hierarchy.
I'm not advocating putting everything into one directory. I'm not advocating organizational structure per project. I'm advocating a freer and more reasonable use of directories as an organizational tool.
Re: The Number One Ill Of Java ...
In my last example, the "/com/acme" portion of the directory structure is arbitrary and excessive and wasteful and irritating and serves no useful purpose what-so-ever, given that every thing in the project falls into the com.acme.* package hierarchy. I'm not advocating putting everything into one directory. I'm not advocating organizational structure per project. I'm advocating a freer and more reasonable use of directories as an organizational tool.
Every thing in THAT project falls into the com.acme.* package hierarchy AS IT IS RIGHT NOW.
What if you make a package that is not in com.acme? What about net? Or org?
Maybe a lot of people would find your "freer" and "reasonable" way "arbitrary and excessive and wasteful."
Your complaint is subjective and you have not specified an alternative. This issue does not take long to understand. If you are "helping" people understand it, they are stupid.
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
I think that if you could have a single directory called com.acme.product.client that would be less wasteful and still be easy to navigate.
Seems to me that a request for improvement in Java 7 or 8 is needed :D
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
Re: The Number One Ill Of Java ...
All that I'm saying, people, is that when you work in the Marketing devision for the Mexico City branch of the GUI Research subsidiary of the International Widget and Gadget company, which uses the internationalwidgetandgadget.com domain name, and you are writing a billing application, where all your classes must live in the (I put some spaces in the package name so that it will wrap instead of going all the way to the east coast) package
com. internationalwidgetandgadget. guiresearch. mexicocity. billingIt doesn't make sense to put everything in a
com/
internationalwidgetandgadget/
guiresearch/
mexicocity/
billing
directory hierarchy. I still haven't heard one good argument that convinced me that this directory structure is necessary.
Re: The Number One Ill Of Java ...
It doesn't make sense to put everything in a
com/
internationalwidgetandgadget/
guiresearch/
mexicocity/
billing
directory hierarchy.
So you'd rather just have...
billingand then have some way of telling the compiler to prepend...
com/
internationalwidgetandgadget/
guiresearch/
mexicocity/
...for you.
Then why didn't you say this in the first place.
I can see that this is a semi-reasonable request and as such should be suggested to the people who are working on the next versions of Java instead of just griping about it.
I'm not sure that such a scheme would be without its problems (Maybe someone could point them out)
Personally, I don't mind creating the extra directories - I simply consider it to be specifically stating my intent, rather than leaving other developers to guess what I meant.
Re: The Number One Ill Of Java ...
I'm very glad you are seeing my point. However I don't think your "Then why didn't you say this in the first place?" comment is fair to me. Just look at my original post:
"I have a directory full of Java sources right here. Why do I have to tell javac or my IDE that the sources are three directories up?"
What else need I say?
Re: The Number One Ill Of Java ...
Don't Repeat Yourself (DRY) and coding by convention are compliments.
DRY is a heuristic, not an ideology.
With all design, we engineers have to balance competing constraints and goals. Hence the conflict. Though, I have to admit, that it would have never occurred to me to question/challenges Java's obviously correct design choice to have isomorphic packages and file structure. This innovation has been an unqualified good.
Perhaps these spurious tangents are productive, if only to remind us why things are the way they are, so that we don't take it all for granted.
Cheers, Jason