Live data from Hacker News

Everything that's wrong with Java in a single class

plus.google.com

121–130 of 159 posts

Re: Everything that's wrong with Java in a single class

#121
post #22

I hate this kind of post. It's the tech equivalent of "You're a stupidhead". If you want to criticize Java then at least make some meaningful points. Just off the top of my head: - 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…

In his defense, I don't think the long class name is the problem he's pointing out.. it's the over-patterned, over-generalized nature of something that barely does anything. The class's description is "Convenient proxy factory bean superclass for proxy factory beans that create only singletons." Seriously? That's fucking hilarious.

Given that Spring is mostly used via annotations or config files, yes this is indeed useful. It helps to know what you are criticising before you show your ignorance.

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...

Re: Everything that's wrong with Java in a single class

#122
post #37

And this is positively lightweight compared to J2EE which Spring superseded.

Take a look at J2EE 6 - you might find it's Spring which is the heavyweight these days. Although as of 3.1 at least the need to write your programs in XML is going away...

I'd argue that the right time to start writing Java EE applications is right now. With Java EE 6, JBoss AS 7 and frameworks such as Arquillian, Java EE is a pleasure to work with.

Re: Everything that's wrong with Java in a single class

#123

Earlier quoted context omitted.

I guess there's a rule in place that hides the down arrow for comments in reply to my own or something. Anyways. I'd downvote if I could. The guy is almost certainly not an idiot. That's a rude, shitty thing to say. 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…

I've used Java for 10 years. I've never used Spring. I've never created an AbstractFactorySingleton. I've never used XML. There's nothing in Java that says you have to use anything in particular, apart from the runtime (Extremely solid), and the basic language syntax (IMHO nice enough). OK, maybe they're not an idiot. Maybe it's warranted. I'd say it's probably over engineered stupidity though. Even so, the title is…

If you don't know what it's used for, or the purpose it was written for, then you aren't in a position to judge if it's stupid or not. I can assure you, it has a purpose, and that purpose is not stupid. The fact that the reason for the class is somewhat obscure and somewhat of a corner case does not make it unnecessary.

Re: Everything that's wrong with Java in a single class

#124

Earlier quoted context omitted.

The class combines no less than 6 concepts / design patterns: - 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…

Overengineering at it's best.

Until, of course, you find you need to use it. Of course, you'll probably never need to use it, nor will you ever see it being used in your particular situation. But hey, it's all over-engineered nonsense, right?

Re: Everything that's wrong with Java in a single class

#125
post #22

I hate this kind of post. It's the tech equivalent of "You're a stupidhead". If you want to criticize Java then at least make some meaningful points. Just off the top of my head: - 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…

> But long class names? Really? Is that all you've got? Who cares?

Is that the only thing you think is wrong?

Re: Everything that's wrong with Java in a single class

#126

Earlier quoted context omitted.

Thats a gross comparison of languages. 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…

Perhaps this isn't quiet HN quality of a comment, but I'd love to go to a grey scale screen. I've been trying to figure out how to do that for years. Never could. The simplicity of it would be wonderful. 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 s…

I tried server-side development in Java, didn't like it at all. I'd pick Haskell or Erlang over it in a heartbeat.

You can't easily build fault-tolerant distributed systems using only classes without concepts such as function purity and data immutability. Java's type system also happens to be neither sound nor correct; casts are everywhere and NullPointerExceptions can fly around. You're constantly working against the language to write safe distributed code. If Java was safe as a language, it wouldn't require so much debugging time. Haskell was an eye opener for this.

For systems programming I now use exclusively C and D. In the end, Java is only a viable option when you don't know any better. Most Javaland programmers I know of also happen to be blub programmers. They don't know unix, regex, functional style, don't write tests and the list goes on. They do, however, know Agile and UML.

Maybe that's what I don't like about Java. It's culture killed technical knowledge and replaced it with bureaucratic management.

Re: Everything that's wrong with Java in a single class

#127

> "it's not java's fault" (from multiple comments) 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 c…

It is true that "Java culture" leads to this case of design pattern abuse, but you don't have to do all that when using Java.

I dare you to find this kind of atrocity in Play Framework 1 (written fully in Java) or in Play 2's Java code.

Re: Everything that's wrong with Java in a single class

#128
post #74

Earlier quoted context omitted.

In his defense, I don't think the long class name is the problem he's pointing out.. it's the over-patterned, over-generalized nature of something that barely does anything. The class's description is "Convenient proxy factory bean superclass for proxy factory beans that create only singletons." Seriously? That's fucking hilarious.

Yeah, but that's just an over-patterned object-oriented design. This has nothing to do with Java specifically.

Hardly. Firstly, AOP is a very effective and useful programming technique. It's used in a lot of places, and without it OOP would be considerably harder than it necessarily needs to be.

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.

Re: Everything that's wrong with Java in a single class

#129
post #67
post #22

I hate this kind of post. It's the tech equivalent of "You're a stupidhead". If you want to criticize Java then at least make some meaningful points. Just off the top of my head: - 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…

The title should have been "Everything that is wrong with Spring ... ". Then it would not have been especially accurate, but more accurate. I like Java better than I like Spring. Spring made a framework out of an idea, but not all ideas should be packaged. Ideas can also be embraced. Dependency injection is an idea that should be embraced, but not as a packaged solution. It is a pattern, not a a software project.

Actually, it would then have been entitled "A class that extends the Spring AOP easily and unobtrusively", or probably just as accurately "everything that is right with Spring".

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.

Re: Everything that's wrong with Java in a single class

#130
post #22

I hate this kind of post. It's the tech equivalent of "You're a stupidhead". If you want to criticize Java then at least make some meaningful points. Just off the top of my head: - 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…

It fascinates me that I also believe that Java has serious issues, but I differ on dimensions.

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.

Post reply on HN