So I’m working on two projects these days. The first is an extremely business-logic heavy application. It was originally implemented in PHP, but I’m writing a Web service that implements the same logic in Java. The other is a code review of an EJB-based application. I’m reviewing the source code to find potential security problems, and even though I’ve looked at hundreds of files, I honestly have no idea what any of the Java code is for.

I know that many people love PHP, and for some applications, it’s great. WordPress is a perfectly fine application written in PHP, because it’s all about slapping a Web interface on a database. PHP is great for that. However, implementing even trivial business logic in PHP is rather painful. In my Java version of the application, I access the business logic in the following ways:

  • Via JUnit for unit testing.
  • Using a standard Java application for running batch regression tests.
  • Via a SOAP-based Web service.
  • Via a proprietary Web service implemented using a servlet.
  • From a Struts action. I have a Struts-based Web application that other people can use to exercise the business logic.

Chances are there will be other ways to use the business logic later. I know that hardcore PHP users will tell me that you can do all of those things with PHP, but the point is that doing so isn’t organic to the PHP way of doing things. Thanks to good tools like Eclipse, it’s easy to make some changes to my application, run my JUnit tests from within Eclipse to make sure I haven’t broken anything (and fixed whatever it was that I intended to fix), and then make a build and deploy it to the server. When I run into thorny problems in my logic, I can use the debugger to step through my code and root out thorny problems. For this application, Java is wildly better suited to my purposes than PHP. At the same time, my other project is a useful tonic against Java triumphalism.

The parts of the code base that I’m reviewing that I’ve seen so far are pieces of a massive (thousands of classes) application written to run under IBM WebSphere. It is a perfect illustration of why EJB is a hateful morass. Most of those thousands of classes are various views on the same core objects (granted, in this application, there are many core objects). Even though I’ve already reviewed hundreds of classes, I haven’t seen one yet that has any actual business logic in it. Right now I’m just praying that all of the classes were generated, because I would have jumped off a building if someone had asked me to write all of these files by hand. Reviewing them is bad enough. (I suspect that they were generated, because rather than importing classes at the top, in these files the full package names are used whenever a class is referenced. The package names and class names are very long, but still use abbreviations throughout. That makes the code nearly impossible to read.) I don’t know enough about the code to know how it could have been implemented more cleanly, but there must have been a way. Maybe they should have used PHP.