Slava Pestov
Slava Pestov
Slava Pestov's Weblog - Factor, jEdit, and more
All | Factor | Java | Languages

20041121 Sunday November 21, 2004

Why I don't like Java

I've been working with Java for 7 years and written hundreds of thousands of lines of code, and I think I can safely say I'm done with Java. I'll keep maintaining jEdit and plugins indefinately, however, I won't be writing any new (open source) projects in Java. (Commercial is another matter altogether).

So here are the reasons:

Static typing is limiting. For example, if you want to write a dialog box whose parent can either be a dialog or frame, you have to write this code:

public GrabKeyDialog(Dialog parent)
{
	super(parent);
	init();
}

public GrabKeyDialog(Frame parent)
{
	super(parent);
	init();
}

private void init()
{
	/* Actual construction here */
}

Similarly, if two classes happen to have similar methods but their designer didn't think to implement a common interface, you have to duplicate code that calls them.

Arrays are broken. Why do we write System.arraycopy(...) and not array1.copyTo(array2,...)? Because arrays are not a real type, and cannot have methods.

Primitives -vs- values. A double-whammy when combined with static typing. There is this weird distinction between object types and primitive types -- there is no type that all values are an instance of. For example, you cannot write a method like this:

public number max(number x, number y)
{
	if(x > y) return x; else return y;
}

Instead, you do this -- no joke, this is straight from java.lang.Math:

public static int max(int a, int b) {
	return (a >= b) ? a : b;
}

public static long max(long a, long b) {
	return (a >= b) ? a : b;
}

public static float max(float a, float b) {
	if (a != a) return a;		// a is NaN
	if ((a == 0.0f) && (b == 0.0f)
		&& (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
		return b;
	}
	return (a >= b) ? a : b;
}

public static double max(double a, double b) {
	if (a != a) return a;		// a is NaN
	if ((a == 0.0d) && (b == 0.0d)
		&& (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
		return b;
	}
	return (a >= b) ? a : b;
}

No multiple dispatch. Instead, we must use crappy hacks like the visitor pattern.

Design patterns. It all amounts to this -- instead of adding expressive features to the language, the Java designers decided to focus on promoting code duplication, aka design patterns instead.

Edit/compile/run cycle. Yes, I know there is hotswap and such, but it is a hack. There is no real support for incremental development in Java.

No interactive top level. This is my biggest beef. Once you discover programming with a REPL, you cannot go back.

( Nov 21 2004, 11:21:31 PM EST ) Permalink Comments [10]

Trackback URL: http://jroller.com/trackback/slava/Weblog/why_i_don_t_like
Comments:

Some of us have learned to live with the limitations because the languages that don't have the limitations are only for academia. No company would pay you to use them.

It's too bad you don't support open source anymore - just because of a few limitations in the programming language.

Good luck

Posted by 12.223.246.125 on November 21, 2004 at 11:53 PM EST #

I code Java when I'm paid to do it. And I definately will continue writing open source, just not in Java (except jEdit, which I will continue to maintain). Since nobody pays me to write open source, I need other incentives, like ease of development, and this is where Java fails.

Posted by Slava Pestov (24.42.111.220) on November 22, 2004 at 12:21 AM EST #

Hi slava,
So which lanaguage do you prefer to code in right now? I'm gaining a lot of enjoyment out of ruby.

biv aka nickf

Posted by nickf (203.217.23.60) on November 22, 2004 at 08:52 AM EST
Website: http://jroller.com/page/nickf #

Well there's not just ease of development in programming languages. Some of the griefs you have against Java just seem to be type-saving tools. I really love languages like Ruby or Python but there are some things that I won't do with them... and it goes the same with Java. I really don't think you can use only one language to rule'em all. I am for instance still very very disappointed by UI toolkits for Python (even though I quite like PyQT).

Posted by Romain Guy on November 22, 2004 at 04:58 PM EST
Website: http://www.progx.org #

nickf had a worthwhile question, Slava. What do you propose, if not Java?

Like you, I became frustrated with the inelegance of the Java language. After casting around for a realistic alternative, I switched to Python. I'd actually prefer Lisp, but library availability and standardization in the Lisp world are dismal.

So far, my only major complaints about Python are that it has mediocre performance and no Lisp-like macros.

It irritates me that I'm forced to descend to C and sometimes C++ for the most performance-critical sections of code. Trying to pick up someone else's open source C or C++ code base and write a Python wrapper for it or use its existing Python wrapper is often an exercise in frustration due to the well-known robustness problems with those languages. In Lisp, theoretically, I could descend to a more performance-oriented style of programming in performance-critical sections, without having to cross a language barrier.

Posted by Robert Maxler on December 01, 2004 at 02:01 AM EST #

Different languages are geared towards different goals. Java is more fit for enterprise solutions or server level applications. It is simply impossible to win all sides, and so I think it is important that one states his/her intentions in the industry before listing the disadvantages of a programming language.

Posted by Rex on December 07, 2004 at 04:09 PM EST
Website: http://contex.sourceforge.net/mt #

Different languages are geared towards different goals. Java is more fit for enterprise solutions or server level applications. It is simply impossible to win all sides, and so I think it is important that one states his/her intentions in the industry before listing the disadvantages of a programming language.

Posted by Rex on December 07, 2004 at 04:12 PM EST
Website: http://contex.sourceforge.net/mt #

Rex: Are "enterprise solutions" (whatever they are) easier because of any of the limitations he listed? I can't imagine how.

Posted by k (4.16.250.14) on January 04, 2005 at 05:59 PM EST #

What language is REPL?
Please, give me a link on official sait.

Posted by Sergey Tugarinov on February 26, 2005 at 03:08 PM EST
Website: http://ruteam.ru #

To be exact, he said coding _with_ REPL, not in. REPL is a Read-Eval-Print-Loop or so called Top-level. This kind of thing can be found in several (dynamic) languages, such as python, lisp and numerous others. It enables coder to test code in a very fast and interactive way. For example you can paste a single function from your code to REPL and then you can give it some test input and see if the output is correct, no need to write debug messages, save, compile, run. In many REPLs you can also debug and fix errors "on fly" and then continue execution. It really is addictive ;)

Posted by S. Vuori (130.234.176.170) on March 07, 2005 at 06:51 AM EST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: Disabled

Please answer this simple math question

8 + 87 =


Archives
Language
Links
Referers