Someone on StackOverflow suggested we think of ugly Java class names as poetry; he provided an example:<p><pre><code> InternalFrame InternalFrame
Title Pane,
Internal Frame
Title Pane.
Maximize Button Window,
Not Focused State.
</code></pre>
<a href="http://stackoverflow.com/questions/1697215/what-is-your-favourite-java-api-annoyance" rel="nofollow">http://stackoverflow.com/questions/1697215/what-is-your-favo...</a>
I just did a quick analysis of a system with a large number of globally exposed names written in C.<p>About 1000 functions in all (so that's <i>just</i> the globals), of those a hundred have names > 30 characters. There are some real 'gems' in there, consistency - even if self enforced - has a price. The record holder weighs in at 53 characters, it (fortunately) drops off quickly after that.<p>There are only 2 things hard in programming, cache invalidation, naming things and off by one errors.<p>Personally I think this name is bad because in spite of the enormous length it <i>still</i> doesn't tell me what it actually does. It just uses a lot of characters to indicate its spot in a hierarchy.<p>Names like these are what gave rise to jokes like 'Q: What is the spelling of bureaucracy? A: J-a-v-a'. Which of course does a dis-service to java the language and the community behind it.<p>I can see why they're funny, but you have to realize that when you get out of the trivial program length domain into projects that are 100's of thousands of lines that this problem will sooner or later rear its ugly head. And I have not yet seen any really good solutions.<p>The things that can help you to extend your runway a bit in this respect are:<p><pre><code> - be consistent
- reduce scope wherever possible
- pick short names for primary objects
</code></pre>
But even with those rules you'll have a 53 letter name in there somewhere... I'd be very wary of casting stones in situations like these without knowing exactly how the person that picked it originally made their choice. Chances are there were a whole pile of external factors dictating this monstrosity and the guy or girl (or the code generator!) that did it never was happy about it either. Laughing at others that have tackled some problem is easy. Coming up with real solutions and doing a better job of it is a lot harder.
Also, in the package com.sun.java.swing.plaf.nimbus, there lies the infamous class InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState (<a href="http://codenav.org/code.html?project=/jdk/1.6.0_22&path=/Source%20Packages/com.sun.java.swing.plaf.nimbus/InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonWindowNotFocusedState.java" rel="nofollow">http://codenav.org/code.html?project=/jdk/1.6.0_22&path=...</a>). Quite a precise name for a class that has only 36 lines.<p>Talking about design patterns, the folks that develop the Spring framework apparently tried to put as many of them together as they could: there is a class named AbstractSingletonProxyFactoryBean (<a href="http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.html" rel="nofollow">http://static.springsource.org/spring/docs/2.5.x/api/org/spr...</a>) in the aop package. And, the class description is no less than "Convenient proxy factory bean superclass for proxy factory beans that create only singletons".<p>Take that, GoF.
You can find quite a few of these, and every time I see them linked I shake my head in confusion.<p>I don't understand what I'm supposed to take away from this. That there exists in the world badly named Java classes? And? Is the implication here that because you found an example of a clumsily named Java class the entire language is an usuable write-off? Or that it's somehow indicative of all Java applications?<p>I know Java isn't cool, but I don't see what is achieved by staring, pointing and giggling because you found an example of its use that is ungainly.
Almost as good as Microsoft Office's tristate enum with 5 states (three of them not supported), where 0 is False and -1 is True:<p><a href="http://msdn.microsoft.com/en-us/library/aa432714(office.12).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa432714(office.12)....</a>
Seems like automatically generated class name. You shouldn't ever see that as a Java developer unless you work for Sun, since this is internal package. The name, though long, seems pretty consistent with the rest of the names in the package [1].<p>If you look at it once more I guess that it is used as a Painter for MaximizeButton located in InternalFrameTitlePane of InternalFrameTitlePane of InternalFrame.<p>How would you name such thing?<p>[1] <a href="http://javadoc.bugaco.com/com/sun/java/swing/plaf/nimbus/package-tree.html" rel="nofollow">http://javadoc.bugaco.com/com/sun/java/swing/plaf/nimbus/pac...</a>
As good or bad as the Java language may be, I think plenty of people are turned off by the Java culture that encourages this to happen. This is a little bit of an understatement since Sun setting the defacto coding standard gives a very strong message to followers.<p>The rest of the world might simply say blah.bah.frame.paint and be done with it.
Here's a query for [\w{60,} lang:java] on Google Code Search:<p><a href="http://code.google.com/codesearch#search/&q=%5Cw%7B60,%7D%20lang:java&type=cs" rel="nofollow">http://code.google.com/codesearch#search/&q=%5Cw%7B60,%7...</a><p>E.g. TraversableResolverSpecifiedInValidationXmlNoDefaultConstructorGwtTest , DeleteContentTypeXmlDocumentResponseDeleteContentTypeXmlDocumentResult , and so on.
This is not a code smell, but something larger, and much worse. Java is fundamentally an imperative language, and these names are evidence of the disconnect between that nature and what people <i>think</i> Java is.<p>One can argue that this is the result of ignorance, that "good" Java programmers will avoid this trap. And yet, for all it's restrictions, it doesn't give much refactoring guidance. The proliferation of patterns (both for creation and relation) in Java is a weakness, not a strength, and the result is monstrosities like this. Training, experience and convention avoids these traps, but why do we create new languages if not to reduce the amount of training, experience and convention that a programmer needs to learn in order to be productive with an environment?
I've only touched Java a bit, but AFAIK it has quite strict package hierarchy system that allows naming and grouping things nicely.<p>Why then people keep creating long class names in the first place? I get it that this particular example might be a generated name, but still, why not just create package hierarchy that represents the code properly?<p>Also wouldn't using package hierarchies automatically lead to a bit better design (more modular, more understandable)?
You've most likely already seen this, but, if not, it's a relevant, great read:
<a href="http://discuss.joelonsoftware.com/default.asp?joel.3.219431" rel="nofollow">http://discuss.joelonsoftware.com/default.asp?joel.3.219431</a>
Some people like to document their code with long name instead of comment. It's an internal class anyway. Why would anyone care?<p>JDK has a superb auto document building tool to extract all the classes in JavaDoc and letting people to find internal classes easier.
I think Javascript also suffers from something like this: functions inside functions inside functions inside functions. If Java is the king (queen?) of horrible naming conventions, Javascript is the prince(ss) of horrible code structure. It might be why both are named Java...<p><pre><code> var foo = function(foo, bar){
var bar = function ( function (x) {
this.something = function (z) {
return function (y){}}}}};
//or something like that. Only a fool would
think the code above is real or even correct.</code></pre>
More information [2007]: <a href="http://www.pushing-pixels.org/2007/11/07/and-the-longest-jre-class-name-is.html" rel="nofollow">http://www.pushing-pixels.org/2007/11/07/and-the-longest-jre...</a>
When I saw the title I thought, _that has to be java_. If it had included a "Factory" or "Manager" in there somewhere I would not have needed to look at the link to verify.
This was obviously generated using the Enterprisify your Java Class Names tool:<p><a href="http://projects.haykranen.nl/java/" rel="nofollow">http://projects.haykranen.nl/java/</a>
Never mind the fact that this is in the com.sun package, and as such should never really have to be dealt with. However, I do agree that anyone who makes a class name longer than three or four words is somewhat demented.
Wow, think they could make that any longer? I mean, I don't think it was long enough. 78 characters isn't long enough, I think it should be at least 96.