Monday, November 24, 2014

I hate Java

I've been programming in Java for over 15 years.

I'm very good at it.

And I still hate it. (Writing below refers to Java 6; newer Java may have solved part of this issue)

Cases in point:

1) Iteration. The inconsistencies about how you do this are endlessly aggravating. There should be ONE SINGLE WAY to iterate. And that means ONE SINGLE WAY to create something to iterate over, when it's not something that already has an obvious iteration sequence.

Sometimes you have a List-behaving group. Sometimes you don't. Either way, I should NOT have to be remembering "ah, for *this* particular thing I have to loop over a Vector, for this one it's an array, this time I get an enumeration, this one is an iterator, etc"

Code examples:

File[] files = new File("some-folder/").listFiles();

Enumeration keys = new Hashtable().keys();

Collection values = new Hashtable().values();
Iterator iter = values.iterator();

Vector xx = new Vector();
for (String yy:xx) { whatever(yy); } //this works fine

for (String fname:new File("some-folder").listFiles()) { something(fname); } // nope, can't do this

2) Lengths of various things.

new File("some-folder/").length

new Vector().size();

Enumeration keys = new Hashtable().keys(); //what? there IS NO WAY to get the length? GGGGAAAAHHHH!!!!


3) Apply a function/method to the elements of a sequence. No such animal.

I'd like to be able to do something like this:

 for (String fname:Apply(FindMethodNamed("xyz"), new File("some-folder").listFiles(), Vector) { something(fname); }

-----------------------------------

I used to program in Lisp, starting 30 years ago. Lisp is beautiful. So clean in comparison. I was twice as good.

need the length of something that could be a list/sequence? (size X

need to do that "Apply" thing above?

(map #'(lambda(obj) (filename-name obj)) (list-files "some-folder/"))

Well, really, you would probably not even do that anyway. There wouldn't be a reason, if you were just going to iterate over the list of files.

(dolist (file (list-files "some-folder/")) (do-something (filename-name file)))

Hmm. Was that that function called list-directory? Been long enough that I misremember.

Rumor is that Java 8 finally has something like this. 8. Rumor was that Java 7 was going to have it. But most of it is a foreign concept for Java. Functions? Functions not tied to a class? Anonymous functions? "Lambda" functions? I haven't been to look, as I have a restriction at work to using Java 6 still (not that I wouldn't like to move forward, but I don't control the circumstances; it was supposed to have changed by now, but personnel turnover in IT have not helped).


Java is a language hacked together by a committee that never met to discuss things like consistency. Damn amateurs.


Granted, when I started with Lisp, it was almost 30 years old, and these issues were long gone, and the formal standard of Common Lisp had just hit the streets. And that was designed by a committee. A committee that "met" many times over some years, and had themselves many years, or decades, of background in various dialects of Lisp. And even then version one isn't quite perfect...for one thing, the Object System isn't included (not because the reference implementation didn't exist, it did, I knew of it, but I hadn't touched it yet). Version two had that, and it was/is better than Java's. Did the Java creators learn from it? Not hardly. Java is C++ minus the really stupid things about C++ from the 80s (another amateur hack that didn't learn from others).

And here I am, I am now full-time a Java programmer. And after this many years, parts of it are still just as stupid as 20 years ago, and will not ever be getting better. And I won't be getting any better at it either.

Fortunately retirement is not that far off...and I still have a huge amount of personal programming to do after that.

No comments: