61 points · by Garbage · 15y ago · 107 comments
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 learn Java.
Furthermore, a lot of far better languages run on the JVM and have Java interop (Clojure, Scala, etc). Strictly speaking you don't have to know Java to use Clojure. But in practice, it's going to make your life miserable if you don't know the Java libs reasonably well.
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 and dynamically. You can see the core of the architecture much more clearly if your default thought is 'I want to pass a function' or 'I want to call a fn based on rutime types.' And then you should convert that to what's implementable in language X (strategy pattern and visitor pattern, respectively for Java). Thay way you don't lose sight of the forest for the trees (and can implement what you're trying to do without cruft in a good language).
- Verbosity. It's bad enough that passing a small fn (1 line of code in a decent language), requires a separate class and 20 lines of code in Java. On top of that the type system is too weak to actually stop most interesting errors but just strong enough to be annoying. And for some idiotic reason, they won't even implement compile time type inference which would save lots of verbosity and maintain code/bytecode compatibility.
As for overuse of patterns - well, to be honest, I sometimes actually wish that my colleagues would learn some (at least basic) patterns. Quite a large number of them wouldn't know how to implement Strategy, for example.
As for your other points.. I don't know. I think this is debatable. 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. Overuse of singletons (and overuse of any pattern for that matter) is certainly a code smell, but there are simply some situations where singletons are appropriate. Or would you argue that this is true for Java simply because of bad design of the language itself?
What I, personally, dislike about Java is it's really bad handling of lists. You see, as somebody working on Java enterprise projects, I constantly have to do something with lists, I fetch them, sort them, filter them, perform operations on certain elements of the lists etc. And it's incredible how verbose and ugly and littered with for-ifs the code gets. Yes, members of JCP EC, we need those closures, and we need them now.
Java is a virus. If Lucene and Hadoop were written in C/C++ you'd be able to easily use them from basically any language. Because they're written in Java, it forces the rest of your code to live in Java land as well.
No need to exaggerate, it's only a few extra lines
functionTakingCallback(new Callback() {
public void fn() {
...
}});
I agree it's verbose enough to be annoying, but hardly a deal-breaker imho.EDIT: Just occurred to me that you might be looking at it from the other side, where you would have to define the callback class. Still, defining a static nested with a single function is only 3 lines of code.
Hardly ever use globals, never use patterns, I think in code , dynamically...
The whole point is to make passing in functions hard. Passing functions everywhere leads to spaghetti code.
As for global state - using singletons is a design decision. If you don't like them, don't use them!
So many people on HN hate on Java just because they've made the switch to functional programming. All power to you, but none of what's good about FP makes Java bad - it's just different.
I'd agree that there are some inherent design issues with Java - I've never liked primitives and I don't like how generics were implemented but other that that, it's a really excellent tool for a number of tasks. Just because it doesn't look like what you like, doesn't make it bad (this reminds me of when Java came out in the first place and all the C++ programmers were saying that it was useless because it didn't have operator overloading. not bad, just different!)
When all you have is Java-style OO, everything looks like an AbstractHammerFactoryInterface.
Seems like you're confusing Java the language, with how some people choose to use Java.
There are many opinions about this on the internet, but most of them are geared towards enterprise developers in large shops; not towards startups.
jdk
textmate / jedit / nano
ant
What else do you need? :/- It has a pretty simple syntax, as it doesn't have too many strange or unintuitive language constructs.
- Its verboseness forces the learner to understand what is going on and be thankful for the magic that more dynamic languages provide.
- It's statically typed so it forces the learner to think about types.
- It's hard to shoot yourself in the foot with beginner mistakes like with C++/C. Still, it's a good preparation for learning C/C++ later.
- Clear compile-time and run-time error reporting.
And so on...
- No. Java has a complex syntax. Take a look at the grammar sometime. It's 10s of times longer than Scheme's (see: http://java.sun.com/docs/books/jls/second_edition/html/synta...). You just like it because it's almost, kind of, a little, like C and C++.
- It is, in large part pointless verbosity. Explain to me how: Map<String, Pair<Integer, Set<String>>> data = new HashMap<String, Pair<Integer, Set<String>>>(); is useful. Explain how 20 lines for a strategy pattern or a visitor pattern is better than just having built in first order functions and multiple dispatch.
- The type system is abysmal (and not sound). Runtime Erasure of generic types? Casts? Nulls?
- I do agree it is better than C++ for most purposes though ;-)
You'd do better in an environment where everything is an Object. (No "primitives" to get in the way.)
It has a pretty simple syntax, as it doesn't have too many strange or unintuitive language constructs.
Confusing language syntax and semantics? Java's syntax is pretty large and complex by any number of objective measures.
Is this an instance of the "start a language war" game?
- 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.
Where? I'm starting to think people dislike Java for the community / way it's used in enterprise rather than anything to do with the language.
There's no push toward threading in the language :/ And NIO has been around for years.
- No way to tell how things are implemented.
What?? Look at the source code. Decompile the class file into byte code :/
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 you don't have the problem, don't use the solution!).
While there are a few nice libraries (e.g. http://jsoup.org/ ), even those usually don't have examples. Especially when you don't know the library yet, it's wonderful to get a few minimalist examples how to use it. Just compare:
Java: http://jsoup.org/
Ruby: https://github.com/hpricot/hpricot/wiki/ or http://nokogiri.org/
While both Ruby HTML parsers have a simple example right on the starting page, I have to make at least 6-7 targeted clicks for Jsoup.
The same even goes for the core libraries. Just look at Ruby's String class:
http://www.ruby-doc.org/core/classes/String.html
And then look at Java's String class: http://download.oracle.com/javase/6/docs/api/java/lang/Strin...
In Ruby, almost any method has a small example. The Java doc only has an example for the constructor...
Absolutely agreed. Java has some weak spots, but the really bad things (and the most criticized things) are not in the language per se.
E.g. the complete over- and abuse of XML for anything. Complex Ant build scripts. The whole EJB disaster (the older versions, that is). Bad APIs (though in all honesty, most of the really bad ones are 3rd party and not from Sun). The over-use of dependency injection, beans, etc. without a justifiable reason.
Many of these things are just stuff we learned to do better by now, for example JSON and/or Yaml over XML configuration, and convention over configuration. That lower overhead and higher understandability are more important than some would be architect's dreams. On some things the jury is still out (e.g. more or less functionality in basic classes like String, List, ...).
Overall, I think some people are overlooking the many benefits Java has made available to the main stream. It's entirely possible to write beautiful Java code, you just have to go the extra mile of leaving the convention sometimes.
Really? Which statically typed languages have you written in? I think Java (together with C and C++, lets not let Java take all the blame here) is pretty much the bottom of the barrel as far as statically typed languages go.
Compare some of the type examples in the threads here with Haskell's type system...
(Is this post meaningless functional programming propaganda? Probably. But for the love of god stop the myth that Java/C/C++ are good examples of static typing...)
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.
http://docs.python.org/release/2.5.2/lib/string-methods.html
There are some absolute doozies in the Ruby documentation, particularly around IO and the Socket hierarchy. String is relatively ok.
The biggest effort would be to learn the libraries and you basically can't do that unless you're regularly writing code that interfaces them. But that you can do from Clojure or Scala or whatever language that runs on JVM.
If you're a newcomer, and you're going to do a website in Python, you soon find out Django, which recommends you to use, lets say, Apache and PostgreSQL. You feel good because you got a sense, immediately, of what you need to know and install to run a website.
Compare that with Java...
I'm using Clojure with Jetty now, I haven't launched yet, and I'm afraid of things like application servers and doing everything with enormous amounts of XML.
Start with Scheme. It doesn't even have proper objects and classes, so you'll be forced (guided, actually, if you go the SICP route) to implement them yourselves. This teaches you in an elegant way about essential concepts in programming, but manages to keep your head clear and unbiased about the many different ways to do things, whereas a language with a strong fundamental paradigm (i.e. Java) may bias you forever.
Then learn C. It couldn't be more different from Scheme, but that's a good thing. It forces you to think about things you thought you didn't reaaly have to think about - such as memory allocation.
With a solid basis in these two languages, you've covered just about every paradigm or building block of programming languages you can imagine. Learning another language then becomes trivial, and for bonus points, you'll be a lot better programmer at those languages too.
If you're a complete newb, learning Java will also introduce you to the C-like family of languages. (Although I say everyone should learn C first in order to appreciate memory management)
Sure, if your goal is to get a job maintaining mainframe systems in banks for the next 30 years Cobol or Java are very good ideas.
On the other hand, there are already huge heaps of mediocre java programmers available for cheap, so it's not like the demand is that high.
Don't ever tell that any C-novice coming from Java. Or you will have fun with interesting array constructs or functions returning pointers to variables created on the stack, etc.
I'm formerly a COBOL developer, now working with Java. Did anyone else think that his main argument for learning Java could also work for learning COBOL? (substitute COBOL for Java in the quote below)
<quote> It's not going to go away any time soon. There's too much momentum. There's no need to worry. Ever since the launch of Java I've heard that it's going to be gone or unusable tomorrow. History shows that just doesn't happen to popular programming languages.
If you learn Java now, you may still be using it 20 years from now. Or 30. </quote>
The java ecosystem seems to have solved this with Sitemesh, a library that implicitly decorates xhtml for you, based on another XML configuration.
I see a few things wrong with this approach. For one, it presupposes all of this nice template work is only ever going to be needed for xml/html. Need to send a text email? Need to make a latex document? Second, it's entirely implicit. This is a common theme with java libraries-- if the usual task is too verbose, usually implicit is the solution. I don't think there's a good reason Java can't be concise and explicit. It just isn't the thing to do.
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.
The second question is will Oracle further drive away developer mind-share?
I think the answer to both of those are self-evident and when analyzed in that light learning Java looks a lot like learning COBOL around the time Java hit 1.2. The cool stuff was happening over in Java which was now stable enough to take off.
I would say the big difference at this juncture is there is no clearly evident replacement at this point. As their was with Java and COBOL, but I do believe the mind-share shift has happened and we are all looking for the next king amount the court.
Then there's the ton of libraries for everything and good tooling.
Of course, the language itself might be a bit too verbose for some people but I'd rather take Java and the JVM then another language where I'm missing some of this.
I guess most people don't differentiate Java the language from the Java Virtual Machine and that's a shame. I could be doing JRuby on the JVM and be happy then drop into Java for some optimized code. Thus, Java just happens to be the "C" programming language of the JVM.
I have always been astonished at VB6 programmers which ignored what a Variant was, when they were using such datatype all the time.
public static void main(String[] a) { System.out.println("Hello world");}
Yeah you're right. That's an insane amount of typing which would take any kid hours.I had to muster up all of my patience just to type all that code out. You're right! Java is so verbose!
Your "argument" if you can call it that, is like people saying lisp is crap because it uses too many brackets.
I was 10 when I learned Java, and it always threw me off having to copy those first two magic lines which I never understood. What is 'public class'? Why 'static'? What even does the word 'void' mean? 'String[]'?!
Sure, after a few months I figured out the meaning of all of those words -- but it wasn't nice having to do that "open up last file I wrote / copy magic header to new file".
I don't think it's wrong to teach Java as a first language, but I think that there are better first languages which show what real computer science is faster than Java does. Less coercion of a language to do what you want and more free-flowing ideas.
Far more important though is how much stuff is in that one line of code that needs to be understood in order for what you are typing to be more than just arcane magic words. Pedagogically speaking that is an awful way to get started, so I think the claim that that is not a great way to teach kids is pretty valid.
To be fair I fully agree that 'Hello world' is not a good way to assess the worth of a language in general, but the ease of getting started is a valid concern when using a language to introduce programming
class M { public static void main(String[] a) { System.out.println("Hello World"); } }
The problem with using this as learning material is that the teacher has to treat the majority of the code as "magic" until the student is ready to learn about classes, access permissions, methods, arrays, namespaces, types and so forth.In many other languages, there's much less boilerplate to handwave away:
print("Hello World")
puts "Hello World"
(println "Hello World")> Your "argument" if you can call it that
From Hacker News guidelines ( http://ycombinator.com/newsguidelines.html):
"Be civil. Don't say things you wouldn't say in a face to face conversation. When disagreeing, please reply to the argument instead of calling names."
class foo { ... }
And that it has to be in a name called foo.java. And that you have to compile it and run it with java foo
instead of simply ./foo
And that startup time of JVM is orders of magnitude worse than pretty much anything else.Training wheels are only necessary if you could hurt yourself by practicing. Where there is no such a danger there is no reason not to start with the "hard" stuff. It's like learning guitar or piano - you don't have a practicing instrument with only two strings/5 keys that always sounds good and forgives errors.