4 Reasons Java Will Outlive PHP (My interview with IEEE...)
I had the good fortune to be interviewed by an IEEE magazine in February to comment on the demise of Java (vs. PHP). A 45-minute interview turned into a paragraph in the article, but I thought that I might put all of my thoughts up on my blog.
Why Java won't be superceded by PHP
- Object-oriented principles (encapsulation) and tools (javadoc, UML) mean that over the lifetime of a software project, Java will:
a) be easier [and therefore cheaper] to maintain.
b) be easier to model & document.
c) allow for easier re-use.
It was mentioned in the article, but I'd like to re-iterate the point here:
I have worked as a consultant for over ten years now. I am rarely going to a client site where everything is working wonderfully. For the most part, I'm getting called to a client site because of some disaster - "We need to get this release done in a month, we've got ten people working on it, and we're not going anywhere..." [sometimes I work on great projects, but often I am cleaning up messes]. I love reading peoples blogs about writing wonderful code that is commented, and unit tested, and completely documented, with requirements, design, and implementation documents. I almost never see these. I frequently walk in to a client site where generations of developers have heaped code on top of code - a favorite saying I heard was "There is never time to do it right, but always time to do it twice" - Meaning that people knew they were doing it the wrong way so that they could meet a deadline, and hoping that one day they'd actually get a chance to do it properly - but that day wasn't anytime soon.
In most cases, documentation at a client site is negligible, but the code doesn't lie, so the best way to figure out how things work today is to go through and understand the code. Typically, for a Java project, I'll run javadoc, I'll import the code into a UML tool, and I'll track down and/or generate an ER diagram for the database schema. These give me a nice high-level view of the application, and a good starting point from which to drill down.
Reading the changelog for PHP, I shuddered when I read the first point for the 5.1.1 release:
* Disabled native date class to prevent pear::date conflict. (Ilia)
This is pretty scary. They had to change the language -- PHP -- the core -- because an established library was already using the name "date". Yikes.
- While PHP has an object-oriented paradigm, the code becomes similar to Java (but missing the benefits of encapsulation with private/protected), meaning that the benefits of PHP in terms of super-fast development of pages are all thrown out the window.
Perl [a language I write scripts in every other day] has an object-oriented framework, however I suspect that 98% of Perl code written today is not object-oriented.
- Java has a large and well established body of software tools that make design and analysis easier. I can programmatically check the quality of code with checkstyle. This can be integrated into my IDE. I know that over time the body of PHP tools will just grow larger and more robust, so in ten years from now, this will be a moot point.
- Java's native support for threads and concurrent programming. There is a huge class of computational problems that are easily solved by breaking the problem up into "workers" who each perform small actions, without needing to worry about the big picture. Workers exist in any kind of "pooled" environment - pools of database connections for example. PHP doesn't support threading, and none of the documentation discusses threading. In fact, as I tried to find documentation about the internals of PHP, I could not find if requests are processes serially or in parallel.
Don't get me wrong. It's possible to write bad Java code. It's possible to write great clean PHP code. The constructs of the languages, however, make it easier to write clean Java code. I have already started seeing PHP code getting passed from developer to developer and going from bad to worse - I can only imagine what these little projects will look like in 10 years.