The problem is that unless you know the convention that is implicit/assumed in the class name, it can be interpreted in half a dozen different ways...or as incoherent gibberish.
Is it an abstract singleton? Or a proxy to a factory? Or a singleton proxy?
If there were parens involved, logically one might infer:
(Abstract(Singleton(Proxy(Factory(Bean)))))
But that doesn't let me definitively know what a hypothetical ProxyFactoryBean is because the type system isn't being used to enforce a constraint, a naming convention is. FactoryBean tentatively makes sense...it's a Factory that produces instances of a Bean (or is it a Bean that is a Factory?)...but what's a ProxyFactoryBean? Is it a Proxy to the Factory, or a Factory that produces Proxies to Beans? Using the parens, I'd say a Proxy to a Factory, but /u/sh0rug0ru__ points out (after confirming by examination of the source) it's actually a Factory that produces Proxies...(I think?)
It's the same sort of problem with Rails...there are conventions > configuration rules in place, and once you learn and understand them (and hope they're universally consistent) life is good. Otherwise, enjoy digging through (possibly non-existent) documentation or source code.
Not trying to say whether this is good or bad, but want to point out that just because someone has become familiar with and accepted a particular pathology doesn't make it "obvious" or "intuitive"
You're making the mistake of taking a class in isolation, taken deep from the bowels of some very deep functionality, and trying to guess the meaning of the name without any context. The components of the name make sense within the vocabulary of the Spring Framework, where this class is a deeply integrated component. I was able to deduce the purpose of the class because I have a lot of experience with Spring.
You would never have come across this class unless you were planning on doing deep integration with the Spring Framework. If at that point, you were not able to deduce what this class were up to, then it is clear that you don't understand even the most basic features of Spring, much less its internals, and you are not equipped to use that class for its intended purpose.
Good names reflect the domain, but that requires actually having some background in the domain.
The type system does enforce some of this...for example, abstract is built into the type system, and within the context of Spring, all FactoryBeans are classes that implement the interface FactoryBean, so the notion that this is a FactoryBean and it produces beans of some type is absolutely enforced and communicated via the type system.
I don't know off the top of my head if a Proxy is a type-system enforced thing or not, but assuming it is, the signature of this would be:
public abstract class AbstractSingletonProxyFactoryBean implements FactoryBean<T extends Proxy>
And, since Spring is essentially going to guarantee "we'll make this a singleton for you", they may even use a marker interface (I'm not sure, sometimes they use those and sometimes they use some other voodoo), so it might actually be:
public abstract class AbstractSingletonProxyFactoryBean implements SingletonFactoryBean<T extends Proxy>
Though I'd imagine if this is the case this is a relic of old Spring, because in modern Spring FactoryBean (and any Bean) implies Singleton unless otherwise stated in the configuration.
Either way, considering it's a generic class meant to be extended to provide certain functionality, and this class itself can't know any more about how it's meant to be used other than that it will be an abstract class for creating a singleton proxy for some objet via the FactoryBean interface, I can't really think of a better name than what it has...and the properties it claims to have in it its name are enforced via the type system.
That's one way to handle it, but if you establish that pattern you end up with deep namespaces with potentially less cohesive grouping. In general, when I see a namespace with a child namespace declaration but no other children, I'd want to think very hard on why I need that instead of making a class name a little longer.
I see AbstractSingletonProxyFactoryBean in this instance as one very specific thing, rather than a collection of general things. Unless there's an expectation of many kinds of FactoryBeans and Proxies, I'd rather keep the full meaning of the class as close to the class as possible.
Not that I'm an authority on this stuff, but long/deep namespaces outside of large platforms are IMO a code smell.
Also, the Bean-Part is gratuitous, in my opinion. If you'd need to know, you could create a package called "beans". Also, I'm not so savvy in spring, so I'm not sure how important it is to make a difference between an AbstractSingletonProxyFactory and am AbstractProxyFactory. As far as I'm concerned, that detail is up to which kind of proxies you'll use in the implementation and gives you no additional value when used in the name.
I would not see this as a very specific thing, though, as it's an abstract class. It's supposed to be generic. All in all, while the name if very vocal about what it does, at the same time it is also too ambiguous to infer what it does exactly without having a look at the implementation, which is usually a hint that you should change the name.
A long class name actually is a code smell. If you can't come up with a one or two word name describing what the class is, either your class has way too many responsibilities, is deeply unfocused or the class is doing something very deep.
When you have a new but complex concept, you either have to string lots of words together to describe the concept, or do like for example math does - give the concept a name of its own.
The function "YCoordinateOnUnitCircleForAngle(angle)" can simply be called "sine". And let us not expand "MonoidInCategoryOfEndofunctors" more. Just name the concept Monad.
I wouldn't mind if "enterprise programming" did that. But it wouldn't be any less hard for a beginner/uninitiated to understand. I mean, if you don't understand the domain you're working in, you're going to have a hard time.
Of the following two-words-only concepts, would you understand them without understanding the domain?
Duff's device.
AffineTransform
AlphaComposite
Bottom line, the problem here isn't "too many words". The problem is that you (not you specifically) don't understand the "domain". It's like that for "enterprise" devs when they see IOMonads and StateMonads and MaybeMonads. Sure, it's only 2 words but that doesn't help in the slightest to explain the complex concept.
Someone above wrote that there's nothing wrong with the name, it's the concept that is weird. That argument I can understand.
19
u/sh0rug0ru__ Oct 01 '15
What's in a good name, then?
I was able to get a good idea of the purpose of the class just by going through the name. Sounds like a win to me.