afongen
Sam Buchanan's weblog.

Rant: PHP and Java

I've had a rant building inside me for some months but amazingly it hasn't come out here. It's starting to surface elsewhere, though, such as this message that I wrote to the TCPHP list recently:

After working with dynamic languages like PHP, Perl, and Python, Java feels like a slow-moving behemoth.

My primary complaint against Java is not the language itself, but that the culture of the Java world so strongly favors large, heavy, overburdened frameworks. Frameworks largely developed by companies that would be more than happy to sell you hardware to run your resource-intensive applications. And as much as Java developers talk about testing (the xUnit testing frameworks started with JUnit, remember), trying to test applications running in a servlet container or an EJB contaner is still difficult. Possible, but difficult.

There are signs that some Java communities are waking up and trying to inject sanity and simplicity into developers' lives. Spring is gaining popularity, and even EJB 3.0 looks to be taking a cue from lightweight persistence frameworks like Hibernate. If you have to work with Java, I cannot recommend strongly enough that you read Better, Faster, Lighter Java. In fact, I recommend it even if you're not a Java developer, as it explores important ideas of simplicity that are important for any programmer's work.

As PHP 5 takes many of its cues from Java, we are benefitting from things such as a cleaner object model, a decent exception mechanism, and broader enterprise acceptance. Note, however, that "enterprise" acceptance comes in part as a result of support from companies like Oracle, IBM, and Sun, those same companies that are selling heavyweight application servers and frameworks. In such company, I expect that PHP will always play second fiddle to Java — running PHP inside a servlet container is very cool, but Java is clearly king.

And maybe that's okay. There's no reason to stick with one language throughout the entire application stack. PHP is excellent for rapidly developing web applications; I don't really like to use it for anything else, although I know that some on this list like its CLI capabilities (for that, I'm still a Perl devotee, many of my coworkers are sed and awk diehards :). I still hold out hope that at work I'll be allowed to develop a web front end in PHP, talking to a Java backend — be it through web services (hopefully RESTian where appropriate) or through more direct means enabled by an app server. There may well be benefit to choosing Java over PHP for certain areas of legacy app integration, although I'd be inclined to want to look at using dynamic languages with strong Java integration like Groovy or Jython to take advantage of faster development time.

With interest in PHP from IBM et al, we're also getting some very interesting R & D that builds on work done in Java. A PHP implementation of Service Data Objects, for instance, which is certainly intriguing reading but will likely be applicable only to a limited set of scenarios. I've seen strangely complex Iterators used in PHP code when a simple foreach() would have been enough. I fear that developers will use these tools and techniques in an effort to be more "enterprise-friendly" or Java-like, when they don't really make sense in PHP. Much as has happened in the Java world.

That about sums up how I feel. The more I work with Java, the more I appreciate how productive I am in other environments and dynamic languages.

Expect more on this from me soon.