Friday, March 31, 2006

Having tried it, I am free to knock it

Ask anyone who has stayed awake for thirty-seven hours consuming nothing but Coke and Snickers bars and staring into a green CRT screen, if there is anything glamorous about the world of computer programming. Look deep into his bloodshot eyes, and try to detect any signs of joy among the red streaks. Then, just for kicks, ask him why he does what he does, despite all the pain it's causing. The most positive answer you'll get is, "it feels so good when it stops."

-- The Life of a Computer Science Major

I just changed projects at work, moving from a C++ codebase to a Java codebase. When I joined to Google, all the "hard core" development happened in C++, so, against my better judgement, I sucked it up and tried to be productive in C++. Three years later, the environment at Google is different, so there's real, meaningful work being done in Java, and now I'm taking part in it. I feel like I've finally come to my senses. The only question now is, what took me so long?

I'm not interested in making religious war about languages, but the contrast is too stark not to make note of. Here are some of the joys I've encountered in the past week:
  • Automated refactoring (including source control integration, for automated checkouts of affected files)
  • In-editor highlighting of compile-error typos
  • Code navigation that's unparalleled by emacs
  • Collection APIs that make sense! Holy cow!
And that was just in making one small change to fix my first bug.

It amazes me that anyone on the planet still insists on using a 30-year old language. Java is C++ with all the boneheaded mistakes taken out, and the difference it makes is amazing.

But my point isn't just that Java is better than C++ and you're stupid if you disagree with me. My point is that using Java instead of C++ lets you focus on the more interesting and challenging problems of building great software, so why waste your time with C++? Why waste the time to invoke a compiler to find out that your code has a typo when the editor can just tell you right away? Why manually slog through every usage of a particular function to add a parameter when you can just have a tool do it for you?

Everyone's favorite argument against Java is performance, but that's based on a write-once-run-forever model of software development. Sure, if you were just going to invest a fixed amount of development time in a bit of code and then let it eat CPU cycles forever, you'd want the highest-performance solution you could find (which, by the way, is probably assembly, or at least straight C, but not C++).

But no software ever gets launched and then runs statically for eternity. It gets extended and built upon and edited by dozens of different developers, all of whom have to be able to figure out what you were smoking when you wrote the code in the first place.

The real challenge of software isn't building the first version, it's building the tenth version on a 5-year-old codebase that has been pushed way beyond its original design parameters and no longer fits the mold, written by someone who left the company two years ago and may or may not have written this code on his best day. In C++ codebases, the state-of-the-art for dealing with code staleness is to rewrite the whole thing from scratch. This never works as well as you'd hope -- sure, it seems good for a while, but give your fresh rewrite a year or two to get stale, and you'll find your completely unable to manipulate the code in the face of changing requirements. In the language of essay cited above, the complete rewrite is a Jello Hour solution.

When I started writing Java code, it took about 3 months before I felt that I was really very facile with it. I wrote C++ code for 3 years, and I still feel like every line of code was a matter of poking myself in the eye with a sharp stick.

The best thing I can say about my time writing C++ code is that it feels so good to have stopped.

No comments: