November 25, 2005

Why Java Sucks: Notes on Learnability and Ease of Use

Many people (including jwz) have written a great deal on the topic of why Java sucks. In general, I tend to agree with most of their comments, but there's an additional consideration that I think is pretty important: "learnability," or, to use a phrase actually present in the English language, ease of learning, and by extension, ease of use.

In many cases, Java has become a first language for students of Computer Science and programming. A first-time student sits down to write the traditional "hello world" program, so he/she writes:
public class HelloWorld {
	public static void main(String args[]) {
		System.out.println("Hello World!");
	}
}
He/she saves it into a file called HelloWorld.java and says:
javac HelloWorld.java
java HelloWorld 
    [Why not HelloWorld.class like every other 
    unix command-line application? No-one knows.]
For what should be an incredibly simple program, the student needs to understand access modifiers, classes, class names, objects, static methods, the main method, method parameters, arguments to a program, Strings, arrays, arrays of Strings, the Java library, the System class, compilers, interpreters, and classpaths, plus assorted syntactical details such as how curly-braces work and when a semi-colon is required and when it breaks the whole program to include one. Only one fifth of the code even relates to performing the actual task that the program is designed to accomplish. That's an awful lot to learn just for HelloWorld. Just wait until they get to inheritance and polymorphism.

Now, of course, one can hand-wave through all those parts and just tell students to focus on a few key details. However, when you expose students to a big mess of confusing code that they cannot possibly understand without a good deal of study as their very first exposure to programming, they tend to get just a little bit discouraged. An elementary school math teacher would not tell his students, "just ignore the Calculus and Trig in these problems and focus on the simple addition and subtraction," so why are Computer Science students forced to learn this way? What if they could just write their program in a much simpler format? Something like:
print "Hello World!";
Here, there's only one thing to focus on. Indeed, there's only one line in the whole program. Students can learn what they need to learn, and not have to worry about any of the other features of the language. When they need them, they can learn them.

Of course, this is about more than just learnability for new programming students and even learnability for new Java programmers. Ease of use is an issue that all programmers face. If I need to write five lines of code and consider a paragraph-long list of programming topics just for Hello World, how easy can it be to whip up a short script to handle a simple task?

Programming languages should be easy to learn and use. If I want to write a program that prints Hello World, then my program should look like that's what it does. One of the things that makes programming relatively easy to pick up (at least in my experience) is the Do What I Mean-ness inherent in the process; you give the computer some steps to perform, it performs them, and you're done. Java destroys this, forcing you to consider a whole host of other programming concepts that are unrelated to the actual problem you want to solve. A good programming language should offer the greatest set of tools while providing the fewest number of distractions, allowing you to focus on the problem at hand. Java cripples the programmer by eliminating useful tools and forcing the programmer to consider everything but the actual purpose of the program itself.

Besides, I miss typedef.

Posted by zach at November 25, 2005 9:52 AM
Comments

That’s why there’s Basic.

But then some people complain that it corrupts the minds of young programmers. Pft. :)


~Grauw

Posted by: Laurens Holst on November 25, 2005 3:25 PM

Yea, there is Basic, but an even better one would be Perl, as it more closely resembles C/C++ and is extremely learnable.

Posted by: Doug Wilson on November 25, 2005 4:01 PM

Of course in Python, "Hello World" is much simpler:

print "Hello World"

Look, ma, no semi-colon!

Posted by: Screwtape on November 25, 2005 4:02 PM

Python for the win. It's very easy to pick up, but supports complex OOP concepts - look at __metaclass__ if you don't believe me.

My college is planning on moving from Java to Python as a teaching language for CS 5 next year. I approve.

Posted by: andfarm on November 25, 2005 5:33 PM

Java starts out confusing, then when it starts making sense they throw in all the UI stuff.

I agree, this is a horribly complex way to start a language... but coding AWT / Swing by hand is far worse.

Personally, I prefer PHP.

Posted by: BB on November 25, 2005 6:48 PM

At my Uni, we started learning Java through a tool called BlueJ, which is a "click and play" class designer. That simplifies the process of making a "Hello World" program to just a couple of steps.

I agree that Java is not an ideal solution for throwing a quick hack together, but the Uni course is not trying to teach that. Having seen some truly awful code written in a BASIC language as part of a commercial product, I see the point in teaching good OO design right off the bat.

Posted by: Robert Knight on November 26, 2005 3:16 PM

What always annoyed me about learning programming via Java (and BlueJ) in high school was that there wasn’t any interactive mode like in Python.

If you just wanted to experiment with a particular line of code and see what it does, you had to create a whole new class (BlueJ would provide a template for it), write that line of code, and compile it. If it didn’t raise any compile-time errors, you then had to switch over to the main window and run the program. If you encountered any problems there and wanted to tweak your program, you had to compile and redo everything from there.

I often found myself opening up Firefox’s JavaScript Console to see if something would work, before trying it in Java. (Thank goodness I found a way to get Firefox installed on the lab computer, despite my school’s restrictions.) You shouldn’t have to do that when you’re learning your first programming language.

Posted by: Minh Nguyễn on November 26, 2005 3:39 PM

Optimizing a language for "Hello World" is not necessarily a good idea. Many of those "extraneous concepts" may be unnecessary for "Hello World" but they'll be immediately useful for non-trivial programs.

Posted by: Robert O'Callahan on November 26, 2005 9:17 PM

An environment like Eclipse is also an option. There is no compilation step, your code is compiled whenever you save it. Running your program is as simple as clicking on a button. You can evaluate typed-in expressions or run statements in the debugger. You can even modify your program while it is running.

Posted by: Robert O'Callahan on November 26, 2005 9:19 PM

Not Python, Jython!

It has all the benefits and libraries of Java, with the language construction of Python.

Posted by: Greg on November 27, 2005 8:05 PM

If you start somebody with

Print "Hello world!";

The normal barrage of questions tends to be why Print? Where does that come out? Why isn't it in a window. Why are there quotes around it? What does the ; mean?

You can take the time to answer these, they probably won't remember or understand all the answers.

Even if they do understand all that they still won't understand *how* the computer achieves this at a low-level so either way there is a little bit of "don't worry about that, it will come with time."

Which of course, is the same answer to the Java example.

[)amien

Posted by: Damien Guard on November 28, 2005 3:23 AM

Python add some nice habits for the new programmers; specially the use of Indexing tabs.

Posted by: Fred.cpp on November 29, 2005 7:25 AM

Here's the list of Java stupity that I have after only using the language for 3 months:
* ResultSet.getInt(blah) will return null even though the return value type is an int and thus
crash if assigned to the primitive type int.
* A ResultSet object is *automatically* closed when the Statement object that generated it
is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
However...(see next)...
* ...Database connections and statements are NOT (*automatically*) closed when they fall out of scope
(as they should be by scope definition of any object oriented language).
* Even though braces {} are optional on control syntax like if-else and while, they are not optional
on try,catch, or finally.
* The JSP get and set parameters insist on the arbitrary style of capitalizing the first letter
of the corresponding bean function name: I.e.
==> setMyfunc(), and even though the following work: setMYFUNC(),setMyFunc(); this ONE case won't
work: setmyfunc().
* Iterators can not be reset!
* jar files are not found if put in a classpath'd directory. Must be explicitly named.
* JSP errors show wrong line numbers (and I'm not talking about _servlet.java files either).
* getString("MYFIELDNAME") doesn't work on "SELECT MAX(MYFIELDNAME) FROM...". Have to use getString(1).
* Prior to j2sdk1.5: Integer mynum=5; won't work. Have to use Integer mynum = new Integer(5);
Also mynum++; mynum>n, etc won't work. Have to use mynum.intValue()
* Prior to j2sdk1.5 Integer, Double, etc are immutable! can't change value!.
* Java doesn't recognize that the ternary operator will always assign a result so that:
String season = (month>5 && month<10)?"summer":"not summer"; will give you a
"variable season might not have been initialized" error.

Posted by: Rick on July 17, 2006 10:22 AM

Rick, your list of stupidity isn't fool enough, so I suggest you to continue expand it. I also have another bunch of issues you might consider:
* prior 1.5: string.compareTo(not_a_string) throws ClassCastException exception
* since 1.5: string.compareTo(not_a_string) gives "cannot be applied to" error
* o instanceof Object ? null : o always returns null
* assert false fails
* .. continue working on ..

Posted by: Dick on July 21, 2006 6:33 AM

You know, you haven't seen anything yet if you haven't looked at the insanity they call J2EE. If you print out hardcopy for the specifications of all the parts (including related specs like JSTL, etc.), you will have killed an entire forest. It would stack to the top of your cathedral ceiling. And talk about an unintuitive, kludged up HACK! These specs were not the result of a careful design process, they GREW like a fungus. Gawd save us from J2EE.

Posted by: Kalyson on January 13, 2007 1:15 PM

PS That being said, I'd still probably pick it over .net from microslop if those were my only two choices. Why are we always having to choose between the Devil and Beelzebub?

Posted by: Kalyson on January 13, 2007 1:19 PM

Hh. Just got to this from a search.

I agree with the original point. It's dumb to start from an advanced point and to work backwards.

Better to start with something procedural such as Pascal say. Teaches good habits. Plus - you can then simultaneously extend into both lower level and higher level concepts.

The procedural approach is fine for most problems (eg macros) and it relates better to the conceptual basis of computing. State machines, CPUS etc etc.

My other concern is - if you start with the OO paradigm, who is ever going to think of something different. It's like teaching Quantum Mech based on the Multi-World view. Why not start with a neutral approach.

Posted by: Richard Gowan on March 22, 2007 2:35 AM

I searched for "java sucks" and found this page. I am happy a lot of people agree that java sucks. My first programming language was C++ which I learnt by reading this great book "Problem Solving with C++" by Walter Savitch. I strongly recommend that book to anyone starting to learn programming.
I love PHP but my current job needs me to work in Java. I have to put up with this hell for about 1/2 a year :(
PHP beats Java is every aspect. Java is just ridiculous compared to PHP.

Posted by: NA on May 5, 2007 9:23 AM
Post a comment