Wednesday, February 6, 2008

Is Java the new COBOL? No.

I'll bash Java as much as the next guy, but when people start to throw around the 'C' word, that's where I draw the line. Being compared to COBOL is kind of like being compared to Hitler. As Dijkstra said in 1975:
The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offence.
Would anyone say the same about Java with a strait face?

The Perils of Java Schools offers some of the harshest criticism of Java to receive widespread attention. What's the chief complaint? Java is too easy! I'm serious. Joel actually asserts that Java is not difficult enough for a college curriculum. He argues that C++, with its pointer-juggling headaches, is much better at weeding out lesser minds.

This is such a bizarre thing to say that I hardly know where to start.

First off, I went to MST (formerly UMR) where our CS department uses C++ and we're damn proud of it. Therefore, it is with a heavy heart that I admit the following: Yes, Java is easier, but that's not a bug, it's a feature! Making programming easier is a Good Thing.

Second, there actually exist C++ programmers who don't understand recursion. Sad but true. It's even possible (albeit rare) to make it through my school's pointer minefield without being able to recurs your way out of a wet paper bag. Joel is just plain wrong to assume that there is a single "part of the brain" whose purpose is to grok pointers and recursion. Pointers and recursion are not the same. At all.

I'll grant that someone who only knows Java is unlikely to understand pointers, but how bad is that really? Pointers don't help you think in higher levels of abstraction. They exist for the sole purpose of getting in your way. Other respectable languages without pointers include: Lisp, Python, Haskell, Ocaml, and Scala.

Recursion is a completely different matter. Java and C++ both support recursion equally well (or equally poorly). If you don't understand recursion, you don't really understand functions/methods. Period.

Let's assume for the moment that I'm done picking on Joel Spolsky. His real point is that schools should not water down their curriculum, and I absolutely agree. Self-respecting CS departments should fight to keep data structures, operating systems, language design, and graph theory. They should also continue to require calculus. This all has nothing to do with our petty programming language feuds. Despite what we C++ elitists would have you believe, C++ is not an academic language. It is a vocational one. Universities teach C++ because employers want that skill, not because they think it builds character.

Still, in all of his anti-Java rhetoric, Joel never (AFAIK) compared Java to COBOL. That would be hitting below the belt.

What makes me rush to Java's defense all of the sudden? Mostly it's because I'm at home sick with a cold... but here is an equally good reason.
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
MAIN.
DISPLAY 'Hello World'.
STOP RUN.
I can not and will not compare Java to that. Let's look at another example, just to drive it home.
x = y * 2;       // C, C++, Java
$x = $y * 2; # Perl
X = Y * 2 ! Fortran
(set! x (* y 2)) ; Scheme
(= x (* y 2)) ; Arc
These are all fairly reasonable ways to multiply y by 2 and store the result in x. How does it look in COBOL?
MULTIPLY 2 BY Y GIVING X.
I can't even look at that without cringing. COBOL was a horrifically misguided attempt to blend pseudo-code with pseudo-English. Being a "business-oriented language", COBOL had syntax designed to appeal to the managers of 1960. Java was an effort to simplify and enhance C++, designed to appeal to the programmers of 1995.

So remember: Java just kinda sucks. COBOL really really really really sucks. If COBOL were an ice cream flavor, it would be pralines and arsenic. If COBOL were the only programming language I could use, I would leave the field.

9 comments:

Steve Asher said...

That comparison isn't even harsh enough. Arsenic, after all, is tasteless. So even though it would likely kill you, praline and arsenic ice cream would still taste good.

Seriously, that multiplication example looked pretty silly, but I think that there is something to be said for key pieces of code reading like English.

Ray Myers said...

Steve: Well, the original version was "pralines and cat turds", but I cleaned it up a bit.

As for code that reads like English, that's a deep point. This margin is too small to contain my thoughts on that.

Ethan Vizitei said...

Java is definately not anywhere near as painful as COBOL, so I'm right with you on your main points. The one item in your post that I want to lift to the skies as most-righteous, however, is this: knowing what a pointer is and how to manipulate them does not prove anything to anyone about you being an amazing hacker, any more then memorizing a few impressive passages on a piano makes you an astounding pianist. All it shows is that you understand pointers, which you probably won't be using at your job anyway

Chris Gore said...

Hi Ray, I made an account on Blogger in spite of the site's name just to set you straight about Cobol. Back in the day when I was studying Cobol for some reason that escapes me (probably absolutely no-getting-out-of-it required to graduate or something), I learned that I can type such amazing things into that 3270 terminal as:

* EXPONENTIAL DEPRECIATION SCHEDULE, 10% PER CHECKOUT.
COMPUTE COST-DEPR = CP-COST-ORIG * 0.9 ** CP-CHECKOUTS.

Oooh yeah, that is exponentiation. There is no need to make up crap about Cobol when there is so much real crap about Cobol. Cobol is just as painless as Java. And no, that is not meant as a complement to Cobol.

And these comments are too thin for code.

Ray Myers said...

Chris, I am well aware of the existence of the 'compute' verb.

David said...

Ray...

Pointers are damn important.

Ray Myers said...

Dave: Meh ... there may be a case to be made, but you haven't made it. Hey sure, everything is damned important. Curry-Howard Isomorphism is damned important.

David Mattli said...

Well... The argument goes like this.

1. All abstractions are leaky. So it is never sufficient to learn only the abstractions.

2. Any language/environment where you aren't directly using pointers is an abstraction, because computers use pointers.

3. So if you don't understand pointers, it will bite you in the ass because the world is leaky.

Essentially we all live on top of a big tower of abstractions, and each person has a level under which it's all magic.

But if you keep that level too high then you are artificially limiting yourself. Like it or not, you use pointers every day not matter what language you use. So please don't confuse the issue of understanding the concept of "pointers"(indirect addressing) with the daily grind of tracking down memory leaks.

I would much rather use Java on a daily basis than C++, but someone who doesn't understand pointers is not a good programmer.

Ray Myers said...

Way to stick to your guns, Dave. You have successfully copied the null-terminated char array of your opinion into my mind.

while(*i++ = *j++);