Live data from Hacker News

"Should I still learn Java?" Answered: Yes.

beginwithjava.blogspot.com

71–80 of 108 posts

Re: "Should I still learn Java?" Answered: Yes.

#71

Earlier quoted context omitted.

- True; I was just considering the mainstream languages. Yes, if you include Smalltalk, LISP, I'm sure there are better alternatives to learn specific concepts. But Java is used a lot in practice, and looks a lot like other languages used in practice (C++, ObjC, C#, and friends), which in my experience makes students more enthusiastic. - I agree the "generics" are complex and overly verbose. They almost look like the…

Ruby and Python are also mainstream, and both provide saner OOP. C++ templates at least have a purpose and provide extra benefits (e.g. performance, compile-time computations for pre-caching). In Java generics are practically implicit type-casts and nothing else. About verbosity ... clear conventions are a lot more effective for readability and learning. In a dynamic language like Ruby / Python, if you don't know wha…

> Ruby and Python are also mainstream, and both provide saner OOP.

For various other reasons I prefer Python to Java (or Ruby), but there is one thing that Java got right and Python totally messed up: avoiding the disaster that is multiple inheritance.

Of course a much better option is to completely do away with inheritance like Go has done (plus Go combines some of the advantages of Python's 'duck typing' with the static type checking of Java's interfaces).

Re: "Should I still learn Java?" Answered: Yes.

#72
post #19

My main problem with Java isn't the language itself. I think it's a pretty ok language as far as statically typed ones go. My problem with Java is the way it's currently being used. E.g. using annotations to fix things that the language won't let you do elegantly. There's a lot of horrible overengineering for relatively simple problems (you don't HAVE to use GOF patterns, they're just a suggestion for a solution. If…

It says something when Ruby's notoriously shonky documentation is the paragon in an example like this. The comparison with, say Python, is even more illuminating.

Re: "Should I still learn Java?" Answered: Yes.

#73
post #52
post #19

My main problem with Java isn't the language itself. I think it's a pretty ok language as far as statically typed ones go. My problem with Java is the way it's currently being used. E.g. using annotations to fix things that the language won't let you do elegantly. There's a lot of horrible overengineering for relatively simple problems (you don't HAVE to use GOF patterns, they're just a suggestion for a solution. If…

"My problem with Java is the way it's currently being used" That is a good point. However, comparing the way things are done in Java and they way things are done in Ruby is a really bad comparison. Those languages live in different problem domains and were grown to solve totally different problems.

As the article points out, Java itself isn't most popular in the niches it was supposed to fill. I don't think it's really appropriate to talk of what they were grown to solve. What they are actually used for is far more illuminating, and while Ruby is encroaching more and more on Java's "home turf," especially now that JRuby has the momentum and capability it has, you can't really say the same the other way.

Re: "Should I still learn Java?" Answered: Yes.

#74
post #51
post #26

Earlier quoted context omitted.

Most of my work these days is Java too, fwiw. But only because I need Lucene and Hadoop ;-) The main bad habit is a gross overuse of patterns to compensate for language stupidity (see: http://norvig.com/design-patterns/ ). A few particular examples include: - Too much global state. You call it a Singleton. I call it a global variable with a fancy name and a lot more code. - You lose the ability to think functionally…

I agree with you about the verbosity of Java, it's driving me nuts. Also, overuse of XML in java-related frameworks/platforms etc. I mean, when it gets to the point where you have to use complex logic to perform a task, you have to start wondering whether xml is the way to go... As for overuse of patterns - well, to be honest, I sometimes actually wish that my colleagues would learn some (at least basic) patterns. Qu…

> What does too much global state mean? Is having singletons in your application inherently wrong, because they introduce global state? I don't think so.

I do. If you have an hour, the following talk by Rich Hickey (clojure) covers philosophy behind global state being the problem. This is not a code talk and he takes his time getting into it so it's not the easiest talk to get into but it does explain the mindset.

http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hic...

To answer your question more directly:

I believe Java's lack of functions/closures lead to excessive factory use, which tend to be singletonish and so you get the set of dependency injection/IoC frameworks that simply don't exist in other languages but exist in Java due to too much global state. There are other symptoms, but this is the first one that came to mind.

Re: "Should I still learn Java?" Answered: Yes.

#75
post #20
post #10

As someone who rather dislikes Java, I'd still tell others to learn it (but certainly not as their first or even second language - it teaches too many bad habits). The main reason would simply be that a lot of interesting problems require tools/libs written in Java (Hadoop and family, Lucene, etc) if you want to get off the ground quickly and efficiently. Eventually, you're going to need to tweak your tools - so lear…

As someone who programs Java a fair bit, what bad habits do you believe it teaches?

- Strong push towards threading. Before NIO, there wasn't a way to avoid threads if you wanted to talk to multiple sockets. NIO has solved that for networks, but the whole java framework/idioms push you towards threads where it shouldn't.

- No way to tell how things are implemented. I had written a heapsort in Java. It run x40 slower than the equivalent C. I was trying to figure out why -- e.g. was it inlining the things it should? if not, why? It's like Java is a subcontractor that won't answer about their methods - that's a bad habit.

Re: "Should I still learn Java?" Answered: Yes.

#76
post #59

Like others here have said, my main issue with Java is not the Java language itself, but rather with the culture of overcomplexity. As an example, every web framework has the issue of abstracting pieces of templates in a consistent manner. Django solved this by writing their own (simple) template language that supports template inheritance. The java ecosystem seems to have solved this with Sitemesh, a library that im…

Your point is absolutely correct, but I think your example is a little unfair. There are a ton of template libraries that handle inheritance or code sharing in both Python and Java, some restricted to XML, others freeform. Saying that any one on either side has "solved" it ignores the others that have approached the problem from another direction.

For my money, a better example is the comparison between http://www.oracle.com/technetwork/java/index-jsp-135475.html and http://www.python.org/dev/peps/pep-0333/. Or http://rack.rubyforge.org/doc/SPEC.html, for that matter.

Re: "Should I still learn Java?" Answered: Yes.

#77
post #19

My main problem with Java isn't the language itself. I think it's a pretty ok language as far as statically typed ones go. My problem with Java is the way it's currently being used. E.g. using annotations to fix things that the language won't let you do elegantly. There's a lot of horrible overengineering for relatively simple problems (you don't HAVE to use GOF patterns, they're just a suggestion for a solution. If…

It says something when Ruby's notoriously shonky documentation is the paragon in an example like this. The comparison with, say Python, is even more illuminating.

I might be wrong, but in the case of String, not really:

http://docs.python.org/release/2.5.2/lib/string-methods.html

Re: "Should I still learn Java?" Answered: Yes.

#78
post #71

Earlier quoted context omitted.

Ruby and Python are also mainstream, and both provide saner OOP. C++ templates at least have a purpose and provide extra benefits (e.g. performance, compile-time computations for pre-caching). In Java generics are practically implicit type-casts and nothing else. About verbosity ... clear conventions are a lot more effective for readability and learning. In a dynamic language like Ruby / Python, if you don't know wha…

> Ruby and Python are also mainstream, and both provide saner OOP. For various other reasons I prefer Python to Java (or Ruby), but there is one thing that Java got right and Python totally messed up: avoiding the disaster that is multiple inheritance. Of course a much better option is to completely do away with inheritance like Go has done (plus Go combines some of the advantages of Python's 'duck typing' with the s…

From where did you get the idea that multiple-inheritance (in general) is a disaster? Multiple-inheritance is only a disaster when the rules aren't clear on ...

      (a) what you're inheriting
      (b) what you're overriding
      (c) what happens when you try calling super::
Otherwise, inheritance is really useful, and Python scores pretty good on all the above points.

Also, GO doesn't have "duck typing". That's called "structural typing" and it is a lot more limited than dynamic typing. GO is not really object-oriented either.

Re: "Should I still learn Java?" Answered: Yes.

#79

Earlier quoted context omitted.

- True; I was just considering the mainstream languages. Yes, if you include Smalltalk, LISP, I'm sure there are better alternatives to learn specific concepts. But Java is used a lot in practice, and looks a lot like other languages used in practice (C++, ObjC, C#, and friends), which in my experience makes students more enthusiastic. - I agree the "generics" are complex and overly verbose. They almost look like the…

Ruby and Python are also mainstream, and both provide saner OOP. C++ templates at least have a purpose and provide extra benefits (e.g. performance, compile-time computations for pre-caching). In Java generics are practically implicit type-casts and nothing else. About verbosity ... clear conventions are a lot more effective for readability and learning. In a dynamic language like Ruby / Python, if you don't know wha…

There, problem solved.

The problem isn't solved. You now know what the type is for that particular moment. What you don't know are the invariants of the don_t_know_the_return_type() function.

What types/subtypes is can return, whether it can return None, what exceptions it can throw, and whether those will change in the future. That information can only come from a type system and/or documentation. Simply reading the implementation only tells you the current state of the system, not the rules that will govern future iterations of it.

The more invariants that can be expressed concisely by the language itself and enforced by the compiler, the less work is left to the user of the function to review documentation/implementation.

This is one large reason why well-designed advanced type systems are so valuable -- you can express complex invariants using them, and then let the compiler enforce those invariants.

Re: "Should I still learn Java?" Answered: Yes.

#80
post #71

Earlier quoted context omitted.

> Ruby and Python are also mainstream, and both provide saner OOP. For various other reasons I prefer Python to Java (or Ruby), but there is one thing that Java got right and Python totally messed up: avoiding the disaster that is multiple inheritance. Of course a much better option is to completely do away with inheritance like Go has done (plus Go combines some of the advantages of Python's 'duck typing' with the s…

From where did you get the idea that multiple-inheritance (in general) is a disaster? Multiple-inheritance is only a disaster when the rules aren't clear on ... (a) what you're inheriting (b) what you're overriding (c) what happens when you try calling super:: Otherwise, inheritance is really useful, and Python scores pretty good on all the above points. Also, GO doesn't have "duck typing". That's called "structural…

How do you define (and enforce) those rules? My general position when writing library code is that none of my classes should be subclassed.

The very few classes that may be subclassed are documented as such, and the methods that may be overridden are explicitly documented, as well as what behavior is required from the subclass when overriding those methods.

The invariants of complex inheritance hierarchies are very hard to understand. What happens if the superclass method isn't called? What happens if one of those methods is called, but another isn't, and the object is placed into an indeterminate state? What enforces that your subclass -- and all other subclasses -- will conform to these often complex and difficult to describe invariants?

This is very similar to multi-threading with mutable vs. immutable data. By making your data immutable, you grossly simplify the understanding of your system's behavior.

Post reply on HN