180 points · by fpp · 14y ago · 155 comments
- Java logging is a clusterfuck
- Something as simple as wanting symbolic links in a Maven build requires a third party plugin, last updated in 2007 (maven-junction-plugin) that requires something no longer in the central repo;
- No lambdas yet;
- Type erasure in generics and the consequences thereof (eg inability to create generics of primitive types unlike C#);
- Checked exceptions;
- No function references, lambdas, etc (still a year+ away);
- Eclipse is a hot mess (IMHO). And, no, for Java at least, vim/emacs simply are no better. IntelliJ is but for some reason they insist on making it hard to make plugins as their API changes every major version. Jetbrains seems to be going out of their way to make it hard;
And as far as Spring goes, it's probably long in the tooth now but people either forget or never knew just how influential Spring was in the early 2000s. Java at that time really was a hotbed for innovation (believe it or not). It may not have invented DI/IoC but it certainly popularized it.
But long class names? Really? Is that all you've got? Who cares?
EDIT: I don't care about the description either. If anything, it's probably poor text from someone who isn't a native English speaker.
As for the layering, it's nit-picking. I had a quick look and found only one use for this: CacheProxyFactoryBean. Perhaps there was more at some point? Who knows? But the subclass seems to be used in the Spring AOP stuff.
The thing that really bothers me about this is the tone. It's a bit like how among a certain set it's popular to deride PHP. In my experience, people who bother to do that (or simply enjoy it when others do) are nearly always closedminded dogmatic fools.
The class's description is "Convenient proxy factory bean superclass for proxy factory beans that create only singletons."
Seriously? That's fucking hilarious.
"Added a new superclass because you wouldn't believe how hard it was to to create beans that create beans that create only singletons!"
Turtles all the way down.
A factory bean is a class that creates factories. You'll almost never need to create your own as you normally use the ones Spring provide for you. And with annotations, you'll likely never even notice them.
A proxy factory bean is used for Aspect Oriented Programming in the Spring framework. AOP is a fantastic way of doing OOP. Try reading up on it before you knock it. Spring uses AOP via proxies. By using proxies, you don't need to inject bytecode via CGLIB, which while a totally valid way of doing AOP, adds another dependency to your project which you may not want or even need.
Singletons are used by default by Spring, which is an IoC (Inversion Of Control) container. An IoC container is extremely useful as it fully decouples classes from one another - the container handles the coupling and you merely set things such as object creation up via annotations or configuration. One of the considerations needed to be taken into account when using Spring for object creation is to decide whether each object is created once and once only by the factory bean, or if multiple instances should be created. You usually use a singleton bean in Spring - otherwise you have to introduce tighter bean coupling with other beans, which kind of defeats the purpose of an IoC container.
A bean is a JavaBean, which is a very simple but powerful convention used to allow reusable components in Java.
So what does this do? It's a convenience class used to extend the Spring AOP framework should you need to do so without having to make changes within the Spring framework itself. Almost no application programmers will need to use it. However, if you have a very particular requirement for AOP proxy bean creation that is not currently handled by the Spring framework (unlikely) then you will indeed find it useful, and I dare say it is, indeed, convenient.
In short, ignorance is OK. But mocking something in ignorance is pretty foolish, and your foolishness is on full display here.
P.S. incidentally, Spring is now well past v2.5 and in fact the current version is 3.1.x. It helps to read the most up to date documentation when trying to understand something in a framework. The description of the class in the latest documentation now reads:
Convenient superclass for FactoryBean types that produce singleton-scoped
proxy objects
http://static.springsource.org/spring/docs/current/javadoc-a...Secondly, this is a class used to extend the Spring framework unobtrusively if it is needed. Most likely you would never need it (if you are even someone who uses Spring, which I somewhat doubt... If you are then you should really learn more about the framework you use) but there are doubtless folks who may need it at some point for some super complex or out of the ordinary project you haven't even dreamed of yet.
Only if you isolate it from all context. Within the context of how Spring is built and works, it's all perfectly reasonable. As cletus said above, if someone is going to slag Java, they should really pick something to pick on that is actually deserving.
Further, if you accept that Spring is a good idea (which in my opinion is equivalent to accepting that Java has major shortcomings that require something like Spring to overcome) then this class is likely plenty reasonable. Like other commenters have pointed out, frameworks are hard. Java makes them harder. In the context where Spring and Java are givens, I'm sure the author of the above is a very handy chap to know.
Be nicer.
[Edit: To be clear. I want to make sure there's no confusion that the point of my original comment was that the class is hilarious. Not that it's not justified, or that the author is foolish, or that Java is awful, or that Spring is awful. I don't have very strong opinions about any of those things.. other than assuming a committer on such a huge, demonstrably successful project is plenty smart and did the poor chaps who are in the unfortunate position of needing this class a great service.]
- Abstract
- Singleton
- Proxy
- Factory
- Bean
- Interceptors
It's not just a long name. The class makes sense in the context of this framework. The core problem (as others here point out) is that the Java flavor of OOP makes writing this sort of code idiomatic.On the upside, you feel really smart once you grok all these concepts simultaneously. After a couple years this you get to brand yourself a "Java Architect".
Abstract is a pretty basic OO concept. You make an abstract class when you want it to be derived and never used directly.
Singleton is where a class can only ever create one object. Harder than it sounds.
Proxy is where the class interfaces with something else. Again, very useful. Proxies are used by Spring to implement AOP.
Factory - abstracts away the creation of objects, in other words the client object does not need to know how to create objects. It's used extensively in the Spring IoC container.
Beans are object that use simple but powerful conventions of creating reusable components in Java.
Interceptors at used by AOP.
If you use these concepts as they are intended to be used then your code will be cleaner, maintainable and a joy to work with.
I seriously don't think you understand that at the core of Spring is an IoC container - it just so happens that Spring does a lot of other useful things.
So you'd rather see every project that wants to use DI, roll their own DI implementation?
On Ruby, I'm constantly at a loss on how to do logging. Sure, in Rails there's the Rails logger available pretty much everywhere. But if I'm writing a reusable library, I can't count on that. So what do I do? Demand every user of my library configure it with a logger?
The stdlib Ruby logger also has no way to fine-tune log levels by class. In a Rails app, sometimes I want debug level, but I rarely care to see each and every SQL statement. (There tend to be hacks to monkey patch around the common cases suggesting others have been similarly frustrated.) Even if I use log4r or some other logger with more fine-grained tuning, within Rails, everything will be using the same logger object, so the typical Java method of tuning by giving each class its own logger doesn't work.
Bleh. Give me SLF4J with logback any day. When writing a reusable Java library, I really have no qualms about using SLF4J.
Care to explain? Logback is easy to configure and extremely efficient
> Something as simple as wanting symbolic links in a Maven build requires a third party plugin, last updated in 2007 (maven-junction-plugin) that requires something no longer in the central repo;
If you are still using Maven it's your problem. Switch to Gradle and your life will be much better.
> No lambdas yet;
True, but if you really need them use Groovy or Scala. Groovy 2.0 is almost as fast as Java and Scala is fun.
> Type erasure in generics and the consequences thereof (eg inability to create generics of primitive types unlike C#);
True, but doesn't this lack of feature harm framework developers mostly? The same people which the article is critiquing.
> Checked exceptions;
You can just ignore them when you write new code. If you have to deal with code that throws them, just deal with them. Most of the modern frameworks nowadays don't use them.
> No function references, lambdas, etc (still a year+ away);
Groovy, Scala and the favorite kid on the block, Clojure
> Eclipse is a hot mess (IMHO). And, no, for Java at least, vim/emacs simply are no better. IntelliJ is but for some reason they insist on making it hard to make plugins as their API changes every major version. Jetbrains seems to be going out of their way to make it hard;
This is the only point for which I tend to agree. Eclipse is difficult to work with. IntelliJ on the other hand is a valid alternative. These days I mostly code in Sublime Text 2 though.
Logback != "java logging". "Java logging" is some messy combination of JDK logging, Logback, Log4j, Commons Logging, SLF4J, some cruft that fell out of Avalon or Fortress or whatever it was, etc. And then you try to use a library that uses Commons logging alongside another library that uses log4j directly, alongside your code, which really wants to use SLF4J... or you deploy your code, which uses log4j, into JBoss, which configures it's own hacked version of logj4 before your code loads, and you run into needing to figure out RepositorySelectors...
You'd be better off reading from Ludvig Prinn's De Vermis Mysteriis, Friedrich von Junzt's Unaussprechlichen Kulten and the Necronomicon. Ia! Ia! Cthulhu fhtagn! Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!
> True, but if you really need them use Groovy or Scala. Groovy 2.0 is almost as fast as Java and Scala is fun.
> Groovy, Scala and the favorite kid on the block, Clojure
Java's upcoming lambdas will have lazily-evaluated results from its map, filter, reduce, etc lambdas. Both Scala and Clojure already have their lambdas/functions return lazily-evaluated results, but certainly not Groovy, neither version 1.x nor the just-released version 2.0.4. Groovy's closures only return strictly-evaluated results.
In fact, 2.0.4 was released only 2 weeks after 2.0.2 to fix "some important issues with generics with the stub generator, as well as several related to the static type checking and static compilation features". (Version 2.0.3 was skipped because "it was mistakenly built with JDK 6 instead of JDK 7".) It may be "almost as fast as Java and Scala" but it certainly isn't fun or production-ready.
Lastly Eclipse is THE best thing since sliced bread. I LOL'ed when you mentioned vim/emacs in the same sentence. Have you actually used Eclipse on a big code base? It's introspection is such a productivity booster. I've not used jetbrains in a decade, but nothing else out there beats it, hands down. Both in terms of speed and quality.
My tool of choice for Java is however IntelliJ, which is simply light years ahead of Eclipse (IMHO).
I agree.
Eclipse seems to always become unstable once enough plugins are installed. After a few updates and removals it ends up tipping over regularly. I suspect the underlying OSGi plugin system is a tricky thing to get right.
Intellij IDEA seems to "just work".
That said, I prefer coding in Clojure with Aquamacs but I've yet to get Clojure into a production system.
Well yes, logging. There is slf4j though. I think that works, although the fact that one needs a metaframework is... interesting.
Eclipse? I love eclipse. I used emacs every day for 2 years, IRC in emacs, news in emacs, EVERYTHING in emacs. Eventually I got sick of IMAP blocking and interrupting the world. I grew to love Eclipse because I realised I could not efficiently comprehend Java code any more without it.
Over-layering is a serious, serious problem in Java. I think I understand your point of view, but a big part of my job is performing code reviews. It really sh%ts me every time to have to jump through the Service, the ServiceImpl, then the Repository, the RepositoryImpl, the Dao, the DaoImpl and... oh, there's the fricking query. Thanks guys.
My huge problem in Java is that I always find 8 classes where 2 would do. The extra classes do serve a purpose; they fulfil stereotyped, expected roles. In some ways the boilerplace reduces cognitive overhead. In other ways, it really does not.
Personally as someone who reviews multi-million line codebases regularly for a living, I am actually terrified of hordes of new Java developers discovering lambdas or acquiring advanced generics. These things are tactical nuclear weapons of source code obfuscation in the hands of people whose judgement (through bitter experience) I no longer really trust.
Spring is not evil, but it does make life difficult because it's hard to follow references. Fortunately, whenever you see an interface Foo you normally just have to jump to FooImpl. Because it turns out that 90% of interfaces are actually not needed; except culturally, stylistically or dogmatically. Personally I think they're over-used, but that's because my observation is that most interfaces (seriously, 90% level) are implemented only once.
Agree on the checked exceptions though. That was a mistake.
I think actually there is nothing wrong with Java as a language, but without sane leadership the corporate culture of it becomes uniquely byzantine.
Is that the only thing you think is wrong?
A "non-haiku" has been written in its honor:
languages have opinions. Java is designed around the principle of "everything should be a class" which makes everyone's first instinct to have lots of mutable instances with lots of mutable member variables. Turns out this leads to shitty code in the large.
Compare to Clojure, which supports mostly all the same features as Java, but emphasizes them differently. You can use mutable data, but by default everything is immutable. You can have methods and instances, but its easier to just use a function. Java can do higher order functions and closures, but they're so verbose that its better to choose imperative for/while loops over map/reduce/filter, which don't even come in the standard library. Clojure is designed to make higher order functions and expression-oriented thinking idiomatic, java makes this so difficult as to be not worth pursuing even with a team who already understands how to think this way.
Java's design leads people towards code that you're afraid to touch for fear of disturbing state somewhere else which causes failures unrelated to your change. That's why when you need to fix a bug, in Java, people will expose a hook here and there to make a minimum change that they are sure doesn't break code somewhere else. A decade of changes designed to expose little hooks to not break existing code, you end up with a AbstractSingletonProxyFactoryBean with intercepters and proxies and loaders. Nobody is claiming that AbstractSingletonProxyFactoryBean is an abstraction. It came into existence over time because it was the easiest way to fix bugs and adapt to changing requirements while not breaking existing code.
It's definitely java's fault, and all the best language designers know it.
PS Here's a paper that describes a team who migrated a bunch of excel macros to Java, found that they had built an unmaintainable mess, then took the same team and built it in OCaml, and have been using OCaml ever since. http://queue.acm.org/detail.cfm?id=2038036 - OCaml for the masses, Yaron Minsky, Jane Street
You can do all the functional stuff in Java, Clojure is doing exactly that. It will be more verbose, but once you learn the ropes it just looks different, it is not different.
it was a method i extracted from some old code somewhere else while i fixed a bug in it. the functional programmer in me sees opportunities to generalize (and prevent future bugs here), so i try to refactor it into a defaultdict and a higher order function, using guava. 20 minutes later I still don't have working code, i revert, curse the gods because this is a 30 second refactor even in python let alone clojure, and move on, i don't have time for this shit.
its not about it looking different. it doesn't matter that closures and objects are turing equivalent. its a syntax problem.writing functional java code has too much friction and is not worth it.
this is not even getting into how any hardcore functional code needs persistent data structures to be fast, which means a) you need to write your code against a 3rd party collections library instead of JDK provided implementations, and b) any interop with 3rd party code will now imply a conversion (copy) at the boundary.
Still, in case you were interested, I commented on your gist with a potential solution.
Isn't it exactly why it is not good idea (or at least not convenient) to do so in Java, even if functional approach would be best suited for the task at hand?
Of course you can do everything in Java what you can do in Clojure. You can also manipulate strings and generate reports in an assembler, did you know this? It all boils down to how convenient it is.
Java was not designed for functional stuff, that's all. Saying that you can map a function over collection in Java isn't going to change this.
I dare you to find this kind of atrocity in Play Framework 1 (written fully in Java) or in Play 2's Java code.
For a more technically critical look at Java the language, I recently stumbled on this video while watching a Scala talk Martin Odersky recommended in the first few sessions of his new Coursera class... http://www.youtube.com/watch?v=hcY8cYfAEwU
It's pretty meaty, although it looks only at Java 1.0. Many of the criticisms aren't things I would have necessarily thought of first, and it gave me something to think about in terms of what my own priorities are. (For instance, the lack of first-class functions and closures gets no mention at all)
Java the language certainly enforces a certain kind of programming, that Steve Yegge so succinctly identified as a "kingdom of nouns". I'm not sure if that constitutes a culture or not but it does strongly influence the kinds of programs you end up writing in Java. I've experienced some shared technical culture between companies I've worked at that used Java heavily, but of course my experience is just anecdotal.
Here's a blogpost from an HNer that argues there is such a thing as "Java shop politics" and that companies that develop certain kinds of large monolithic software written in Java and C++ tend to share something, which is not desirable. I don't really have enough experience to agree or disagree, but it's an interesting read: http://michaelochurch.wordpress.com/2012/04/13/java-shop-pol...
I found that the whole notion of finding some bad examples of a practice and then offer that as a proof to invalidate the whole practice very distasteful. The lynching mob incited from the blog post's false information just shows how far it can go.
I think any UI designer would tell you that a culture doesn't happen spontaneously. Why do Quora, StackOverflow, and Yahoo! Answers feel like very different products despite providing essentially the same functionality?
You can say this about any language and its community, too, not just Java. And it works both ways. Perl, for all its faults, provides a very easy way to package libraries and a well-organized repository for doing so, hence the comprehensiveness of CPAN packages[1].
Java's culture is a result of the fact that Java-the-language promotes badly designed pseudoabstractions intended to guard against bad design. Java provides broken abstractions because it is itself a broken abstraction - the class is a very poor abstraction over an object, and an inconsistent one at that (Java supports multiple kinds - in the mathematical sense - a design choice which impacts the way people use it).
[1] This is particularly true if you turn the clock back ten years and compare with the state of programming languages back then.
> As others have pointed out, this really should be titled "Everything that's wrong with Java culture ..."
was that the OP didn't actually have much technical criticism of the language. If anything it's not "everything that's wrong" because it's missing a lot. I wasn't trying to defend Java.
Though sometimes amusing examples do help to illustrate, when used carefully to supplement the main point!
[1] http://stackoverflow.com/questions/186964/java-core-api-anti...
Also, many of the abstractions start as good ideas, but they soon become a hammer and everything else becomes an AbstractNailFactoryInterfaceManagerProxy.
Now if you wanted to criticize Spring and cargo-cult enterprise Java development, I think that's reasonable.
"I had a problem and thought to use Java - now I have a ProblemFactory"
Seriously though, if you are going to rehash this tired schtick then at least make intelligent points about the problems with the language. I have been writing Java for over a decade and I can tell you are a number.
JavaDocs is one of the earliest (popular) standard tools for documentation, so I'll give it that, but it suffers a number of problems - problems which are partly relics of the Java language, but that's no excuse.
JavaDocs is too focused on documenting classes, rather than documenting functionality (Python docs, by contrast, focus on modules, which are themselves arbitrary chunks of code with connected functionality).
JavaDocs doesn't make the package/class hierarchy terribly clear - this is intrinsically tied to Java's overcomplicated class hierarchy and needlessly complicated package system, but it carries over into poor documentation as well.
JavaDocs also doesn't have a culture of providing complete examples of code, which exacerbates the two aforementioned problems.
That said, JavaDocs has inspired other good tools, so I'll give it some credit for that and write these criticisms off as vestiges from a time long past.
What is "really wrong with Java", not the language but part of the "culture", is a tendency for writing excessive code and xml, abstraction, mocking, etc. but overdoing things happens everywhere.
And a ridiculous "Ruby culture" thing was a DSL used for BDD called Cucumber. It promised tests that look like English so that analysts could write the tests, but then you had to write backing code so that would work. But a lot of people still use it.
And a ridiculous Javascript thing is Node. Javascript on the server? You have to be fucking kidding me. But now you can get a nice job in SF with JS experience.
Pointing these things out is useless. I make a lot of mistakes. Many publicly and online. People grasp onto "bad ideas", but really they are just ideas later proven to be not as good as some other idea. So, write your "everything that is wrong with Java" classes, SpringSource/VMWare/EMC employees. Nothing wrong with that.
It's more a straightjacket that ensures a minimum of mutual intelligibility, particularly when a developer and domain expert are collaborating. Trying to make a tool that non developers can use to write tests is nearly pointless (selenium remote control for example). But adopting an approach where an analyst can look at what's on the screen and say "Hey, no, that's not right. We have to get the foo form in the file before it goes to bar department, not after." It's also nice in the context of CI, where non developers can look at a status webpage and see the state of an app is without drowning in technical details.
As an aside, my criticisms:
I hate how favors a specific BDD template (As A, In Order, Given, When, Then etc) rather than letting people pick their own language sensible for their project. The product/business people I've put in front of cucumber generally disklike that language, and often feel resentful for it being forced on them.
And secondly, I think the way statements are matched to step definitions via regex is awkward. Regexes in general tend toward frustrating abstraction. Do I want $1 or $2 or $3 or wtf was $7 supposed to be again? They also don't compose well. In my experience this choice ends up making the step definitions a cluttered dumping ground that takes more effort to organize than I'd like.
I think both of these would be solved by using a more proper grammar mechanism, probably PEGs, and keeping the rest of the tooling ignorant about its specific definitions.
It's concise, precise, clear functional description of the class. It's also a profound commentary on the shortcomings of the Java ecosystem.
If you enjoyed this, recommended reading:
http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
.. and thats WRONG!
I admit it is a bit funny to see a class with so many design patterns employed. But nothing about it is difficult to understand and the name is certainly descriptive. I don't see how it can be considered over-engineered without knowing the context. This just looks like one class in a larger framework to me.
public int[] what()[]
{
return new int[0][0];
}If you really want to see something funny look at JavaScript code which combines integers and strings. Things that Java would complain about immediately, JavaScript tries to actually run with unpredictable results.
Java, C++ and whatnot are imperative languages, of course the syntax is gonna be different to declarative languages such as Haskell or Lisp. They're also only alien at first; once you get used to a declarative syntax you never want to write imperative code again. It would be like going back to monochrome after experiencing color monitors.
We have some programmers at work who can't think outside the C++/Java/C# box. They also tend to be the worst programmers even after decades of experience.
In the same way, Java is noisy, I admit that, but it's fast, powerful and fairly easy to understand when executed correctly. I'm not saying you can do the same thing in other languages, but it's a good language for systems, especially middle-ware/server side development. It's horrible for Web Page development since JSPs suck and custom tags never caught on in most development shops (they're used because the framework provided them, but even when .tag files came out few used them to encapsulate screen behavior). But Web Development has moved on to JS on the client and REST on the back, so again Java is pretty good too.
You can come up with ugly names for classes in any language.
After years of consulting I can't remember how many times I've walked into an Enterprise Java Shop(TM) to find TemporalSystemLoadOrganizers, IntransitPredeterminedApplicationUtilitySources, MetaphysicalManipulatitiveQuantityDisorderRecognizers only to find out that at the end of the day these abstract-factory-driven-decorated-decoupled-dynamically-injected-frameworks tend to do such obscure/complicated things as "Update a user's first name" or "Show the last item the user has purchased"...
Again, not Java's fault and no question you can write very fast, beautiful and clear code in Java. I'm sure every language has specific warts and most of them probably reside more with the community than the syntax.
Similar to "nobody got fired for buying IBM", the mindset was that "nobody got fired for building layers of abstraction just in case."
It's the culmination of the second system effect.[1] Without a pervasive unit testing culture, the big enterprise answer to "what if" is "let's add a point of flexibility here."
Obviously, people should be held responsible for building unnecessary abstraction layers like that. They waste time and are often wrongly abstracted, so when you do need to go in to refactor, you end up having to fight the pre-existing "what if" abstraction.
And it's not about the language per se. (You can write clean, simple code in Java, but you would have to write it pretty much from scratch.) It's about Java culture, which encourages this kind of stuff.
And yes, I had been a Java programmer for many years. I used to like the language at some point. But several integration projects made me like its culture less and less.
And that's precisely the issue.
It's a part of a third-party open-source library that implements a "dependency injection container". It's a pretty abstract concept to begin with - of course it's going to need to do high-level, head-in-the-clouds-type stuff that on first glance you think you would never need.
Clojure is not a good comparison, since it avoids fear using immutable state. Ruby/Python is also not a good comparison since, well, it does not respect the privacy of state in any manner. The frameworks that have naturally evolved there, reflect the philosophy of need-to-keep-things-simple (which is the only way to work in a world where state cant be abstracted out).
Perhaps if you ask someone to build a Java framework WITHOUT using the "private" keyword, maybe it will lead to a whole different revolution ;)
The issue with Spring, though, is very real. The key problem that framework authors want to solve is giving programmers the correct slots to place functions in. Oddly, Java is not very good at providing the kinds of slots that seem natural, particularly because of it's lack of lambdas. Plugging a function into a Java project requires that you participate in the inane Type-Name-Game whether you want to or not.
Play this horrible game long enough, and you will get the problematic names that the OP has discovered. And it only gets worse for in-house software.
Maybe the name of the class is long and it's usage (and description of what it does) unclear by non-Spring developers, but know that it's a proof of great understanding of design patterns and of aspect oriented programming.
This is a prime example of what "ravioli code" looks like.
It's probably as easy to read goto spaghetti as it is to try to decipher whatever this class does.
This is common stuff in enterprise software world.
In fact, it was posted by someone who doesn't even know what it's used for. I've read the Spring 2.x manuals from cover to cover, and it's a necessary but esoteric part of the framework.
Is the object managed by this factory a singleton?This is a result of people reading their design patterns book and thinking they've mastered the world, but in reality it's just papering over the cracks of the deficiencies of Java.
I suspect once Java 8 comes out stuff like this will slowly disappear from the radar.