Saturday, September 02, 2006

Language Wars - My Take

Java, C#, PHP - Huh?

Yesterday, I was surprised to read Joel Spolsky's advice on choosing a programming language for your next web app. Here's a quote that sums up his advice:

These debates [about choosing a language] are enormously fun and a total and utter waste of time, because the bottom line is that there are three and a half platforms (C#, Java, PHP, and a half Python) that are all equally likely to make you successful, an infinity of platforms where you're pretty much guaranteed to fail spectacularly when it's too late to change anything (Lisp, ISAPI DLLs written in C, Perl), and a handful of platforms where The Jury Is Not In, So Why Take The Risk When Your Job Is On The Line? (Ruby on Rails).

Youch. I'm from the camp that buys in to the Blub Paradox - which says that different programming languages have different levels of power. And that you can be more productive in a more powerful language. Typically, those that buy into the Blub Paradox also think that C#, Java and PHP don't rate as particularly powerful languages.

I think Joel is suggesting you choose the above set of languages for two main reasons. First, the knowledge base and established patterns needed to succeed in the above languages are well defined. Second, choosing a main stream language increases greatly your chance of scalability.

If you have to debate then the answer is ...

I think Joel's first point is extremely valid. The situation he was describing in his article was that of a bunch of interns debating a language choice. And I think the key point is that if you have to actually have a debate, then you probably should go with the main stream language. Paul Graham didn't choose Lisp to write his app in because he evaluated Lisp and other choices, and chose Lisp. He knew lisp. In fact, he knew it well enough to literally write the book on developing sophisticated extensions to Lisp.

If you have that level of knowledge about a language, then you should know both the advantages and disadvantages of going with your selection. And if you don't know the language well, using a production project to learn about it is almost always a mistake.

So, on this point, we agree. If you have to debate, then choose the mainstream language. If you are a Haskell Hacker, or an Erlang Expert, then by all means, go with your language.

I would add to Joel's advice though, to the interns, is that they should use Java or C# for the main implementation, but to continue to study one of the more esoteric languages. In fact, use it for side projects as much as possible. Why? The techniques you gain from dealing in a diverse set of language can only make you a strong programmer. And of course, one day you will have enough knowledge in that language to use it for your primary web application.

Remember, not too long ago the safe choice was Perl + CGI, not Java Servlets.

On Scalability

The second point Joel makes about scalability I have a bit more of an issue with. He says:

I for one am scared of Ruby because (1) it displays a stunning antipathy towards Unicode and (2) it's known to be slow, so if you become The Next MySpace, you'll be buying 5 times as many boxes as the .NET guy down the hall.

Allow me a proof by contradiction. Assume that if you use all the mainstream practices that everything will work out just fine and you'll have an app that scales without any major issues. Does that work?

Well, I've had the (good?) fortune to run just this experiment. At my last job, in the 2000 bubble, I was working with a company that needed to design a highly scalable system. So what did we do? We followed all the rules. We went the J2EE route, including Web Logic, Sybase, Entity Beans, Session Beans, the whole nine yards. And you know what? The system didn't scale one bit out of the box. In fact, we had to break most of the J2EE rules in order to get it to scale at all.

The bottom line, as far as I can tell, is that writing a the next MySpace is going to take as much art as it is skill. To my knowledge, we simply don't have a guaranteed recipe for designing scalable web apps. You need to be smart, creative and try every trick in the book.

Simply using a language doesn't guarantee anything - you can write Java code that is 10x slower than Ruby code, and you can write Ruby code that generates static HTML files that are 10x faster than Java code. (OK, that's my guess, but from my experience, it seems plausible.)

After my hard learned J2EE follow the pack lesson, I'll be hard pressed to believe anyone who tells me that I can just follow a single pattern to success.

On The Same Page After All?

One last aspect of Joel's article caught my eye and suggested that perhaps we aren't that far off after all. He explains:

FogBugz is written in Wasabi, a very advanced, functional-programming dialect of Basic with closures and lambdas and Rails-like active records that can be compiled down to VBScript, JavaScript, PHP4 or PHP5. Wasabi is a private, in-house language written by one of our best developers that is optimized specifically for developing FogBugz; the Wasabi compiler itself is written in C#.

So there you have it - Joel's own company uses a custom language, not one of the three mentioned above. And today he explained that he did it for the reasons mentioned in the Blub Paradox: because they wanted a more powerful language. (He even goes so far as to cite Paul Graham's On Lisp book, which I did above.)

So what language should write your web app in today? If you aren't experienced in any particular language, then by all means, choose Java or C#. But if I were you, I'd pick an advanced one that you can start learning, so you can take advantage of the advanced features you may be missing out on.

No comments:

Post a Comment