Live data from Hacker News

Everything that's wrong with Java in a single class

plus.google.com

111–120 of 159 posts

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

#111
post #14
post #8

Earlier quoted context omitted.

Right, it's not the fact that you can name things poorly in any language, it's that non-descriptive, overly verbose word-jumble vomit is built and presented seriously and without irony as common practice.

Either it's the people who write Java, or something intrinsic in the design of the language itself that drives people to write code in this extremely verbose way. I've always leaned towards the latter...

A bit of column A and a bit of column B. People who write Java are exposed to rampant overuse of design patterns when looking at examples of a) what the community considers Good Java and b) all over their internal projects. This is partially because Java lives, by design, in a Kingdom of Nouns and partially because there's just no good way in the standard language / library / toolchain to do some things without going really pattern heavy.

For example, assume I've got a list of students, and I want to show all the ones who haven't taken at least one exam, sorted by last name. Here's the relevant pseudocode in Rails:

class.students.select {|student| student.tests.inject(false) {|acc, test| acc || (!test.taken? )}}.sort {|a,b| a.last_name b.last_name}

That just flows from my keyboard as a Ruby/Rails programmer, is pretty much instantly comprehensible to other Rails programmers, and (while others might disagree with stylistic choices, variable names, or whether to use that weird &syntax to do the sort) would be considered "good enough Rails code to ship."

I will take the liberty of pasting my Java implementation into a gist -to avoid breaking HN:

https://gist.github.com/3760402

A nice, svelte 38 line method, which will be reused via copy/paste a hundred places in my codebase.

Incidentally, at my previous Big Freaking Enterprise job, the user need "Make a page for a class where we can see all students who haven't..." would get quoted to them as "No problem, that will cost you $1,000. Are we green-lit to implement or do you want docs written first ($250)?", because the core logic I've shown you is the tip of the iceberg of how sucky that experience is going to be. We haven't even started with the XML files and annotations required to hook the new actions together yet. By comparison, as a Rails developer, in lieu of getting you to sign off on a $1,000 line-item to your next invoice I'm inclined to show you a totally working page and ask you "Is this what you wanted?" because implementing it is easier than talking about implementing it.

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

#112
I guess that almost no one here in the comments uses Spring Framework.

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.

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

#113
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 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…

Agreed, this class is an exception of excellent engineering. Maybe people who don't develop in Spring find it 'wrong', but it's not.

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

#114
post #14

Earlier quoted context omitted.

Either it's the people who write Java, or something intrinsic in the design of the language itself that drives people to write code in this extremely verbose way. I've always leaned towards the latter...

A bit of column A and a bit of column B. People who write Java are exposed to rampant overuse of design patterns when looking at examples of a) what the community considers Good Java and b) all over their internal projects. This is partially because Java lives, by design, in a Kingdom of Nouns and partially because there's just no good way in the standard language / library / toolchain to do some things without going…

student.tests.inject(false) {|acc, test| acc || (!test.taken? )}

can be reduced even further using the all? method

!student.tests.all?(&:taken?)

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

#115
post #36

Earlier quoted context omitted.

Did you read what I said? "vim/emacs are [for Java] no better". This was in part to head off the predictable chimes from some of "all IDEs are stupid, (vim|emacs) is the best thing since sliced bread". My tool of choice for Java is however IntelliJ, which is simply light years ahead of Eclipse (IMHO).

> 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 b…

I m using IntelliJ at home but at work we use yoxos.

Yoxos allows the creation of eclipse profile that make it easier to have stable eclipse.

If you have a lot of eclipse users, I think yoxos is the way to go.

But I still use IntelliJ at home :)

NB: I m talking about this yoxos: https://yoxos.eclipsesource.com/

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

#116

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.

My favorite part is that the first word is "convenient." At the point that you need this class, absolutely nothing about the situation could possibly be considered "convenient."

I read that as sarcasm by the author. I refuse to believe anyone would word it like this without sarcasm.

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

#117
A few days ago there was a discussion about spaghetti code, and in the comments other flavors of pasta were discussed. One of them was ravioli.

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.

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

#118
post #36

Earlier quoted context omitted.

I totally agree on java logging. Lambdas would be nice. Checked exceptions? I love them. 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 qua…

Did you read what I said? "vim/emacs are [for Java] no better". This was in part to head off the predictable chimes from some of "all IDEs are stupid, (vim|emacs) is the best thing since sliced bread". My tool of choice for Java is however IntelliJ, which is simply light years ahead of Eclipse (IMHO).

Yes, I read it and still think it's laughable that anyone would mention them in the same sentence...

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

#119
post #14

Earlier quoted context omitted.

Either it's the people who write Java, or something intrinsic in the design of the language itself that drives people to write code in this extremely verbose way. I've always leaned towards the latter...

A bit of column A and a bit of column B. People who write Java are exposed to rampant overuse of design patterns when looking at examples of a) what the community considers Good Java and b) all over their internal projects. This is partially because Java lives, by design, in a Kingdom of Nouns and partially because there's just no good way in the standard language / library / toolchain to do some things without going…

I don't want to play code golf with you, because I think your point is generally valid, but you can happily and idiomatically reduce the Java method itself to 10 lines with some sympathetic scaffolding from the other classes (this is actually how a lot of code in our game is implemented rather than some theoretical optimum):

  public class Student implements Comparable {
    @NotNull public List getTests() { ... }
    @NotNull public String getLastName() { ... }
    @Override public int compareTo(Student that) {
      return getLastName().compareTo(that.getLastName());
    }
  }

  List studentsWhoHaveNotTakenAtLeastOneTest() {
    TreeSet studentsMissingAtLeastOneTest = new TreeSet();

    for(Student student : getStudents()) {
      boolean allTestsWereTaken = true;
      for(Test test : student.getTests()) {
        allTestsWereTaken &= test.isTaken();
      }

      if (!allTestsWereTaken) {
        studentsMissingAtLeastOneTest.add(student);
      }
    }

    return new ArrayList(studentsMissingAtLeastOneTest);
  }
The point I'm (perhaps ineptly) making is not that Java isn't all that verbose (because it obviously is) - rather it's that you don't get much of a stack of abstraction by default. If you don't take the time to implement that abstraction, you're going to have a bad time, but if you do, it's not appalling.

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

#120
This is a part of the 2.x Spring framework that is used only when you need to use some fairly specific AOP functionality. Given its use is very rarely used by Spring apps I hardly think you can a. say this is a Java issue, or b. say this is even an issue with AOP IoC frameworks.

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.

Post reply on HN