Why PHP (and not Java)?

Almost every week or so, someone asks me: Why PHP? Apparently, you are doing Java too. So why not Java? Do you regret the fact that you wrote Drupal in PHP?

The answer?

No, I don't regret the choice of PHP. Both languages will get the job done, but Drupal's main target audience are not conservative verticals (government, healthcare, banking).

The web is built by millions of individuals, many of which are amateurs. They continuously update, tweak and rebuild their websites. Scripting languages like PHP lend themselves to that, and are widely available at affordable cost. Sun, on the other hand, failed to make Java accessible to amateurs.

It would have been very difficult to get critical mass if Drupal was written in Java.

Itkovian:

One might add that the way in which so-called scripting languages are used lends itself to a faster write-test-sequence. The same can be said for languages such as perl and python. They are perfect for so-called prototyping or rapid development cycles.

Of course, the drawbacks to such languages are well known, the lack of types being one. Strong statically typed languages are usually less error-prone at run time. But no one can deny the fact that PHP has made web development more accessible. Undoubtably, the level of de code will take a hit when non-professionals are at work, but as we all know, being a professional is no guarantee for decent code.

But why the whole Java vs. PHP question load? IMO, most languages are suited, and oftimes made, for a certain category of tasks. It is wrong to try and use a single language for everything. Of course, as languages are Turing-equivalent, they can ultimately be used for all the jobs another language was used for, but writing e.g. Doom in 'sed' is just a bad decision. If you decide to do it anyway, the purpose should be fun. The same goes for websites. If PHP suits your goal, use it, if it doesn't, then don't. But IMHO Java for website development is most often a major overkill.

Of course, enough bits have flawed argueing over these things. So I'll leave it at this.

April 28, 2006 - 20:11
Dries:

Each programming language has its advantages and disadvantages. I deliberately tried not to get into technicalities because any attempt at comparing PHP to Java is bound to be (1) incomplete and (2) subjective. Static type checking, the example you used, is only one aspect of many and has both advantages and disadvantages depending on your priorities.

April 30, 2006 - 23:57
Luc Van Braekel:

Interesting post, and I agree with it.

But you don't mention why those "conservative verticals in government, banking and healthcare" are choosing Java. Isn't that because of:
1) the better scalability of Java;
2) the fact that Java is better suited for complex mission-critical applications, for the reasons that Itkovian pointed out.

If scalability is an issue and hardware cost is not an issue, I would opt for Java too.

On the other hand, PHP runs very efficiently, even on small hardware footprints, is tightly integrated with the web server, and is better suited for agile development by amateurs.

April 29, 2006 - 14:14
Dries:

What makes you think Java has better scalability?

The Java community has an unhealthy focus on the scalability of non-Java solutions. Some of the most popular websites in the world are written in PHP (eg. Wikipedia, Flickr). Scaling a PHP application means scaling your webserver (typically Apache or Lighttpd) and scaling your database server (typically MySQL). These problems are solved and well-understood.

Besides, if your Java-based web application uses a database server, you'll have similar issues to deal with. If you have to scale your database server, it is not because you are using PHP or Java, it is because you have a lot of data to deal with.

April 30, 2006 - 23:04
Itkovian:

I think that the scalability issue is often misunderstood. People claim that Java scales well, because it comes with a load of OO paradigma's and tools that supposedly allow for a better maintainable codebase - meaning that the scaling is inherent in the maintainability. However, writing maintainable code is not only a feature of the language, it's mostly a feature of the programmer. It's quite easy to write obscure, non-extensible and unmaintainable code in Java. The same goes for any language. I've seen Java code that was written superbly, and I've seen PHP code that was written superbly. And I've seen the other side for both languages as well.

The issue remains that people often criticise a language decision without understanding the arguments they bring up. And as the British say: the proof of the pudding is in the eating. I think PHP has proved to be usuable for large-scale projects - as long as the programmers adhere to good coding practices.

May 2, 2006 - 11:12
Dries:

I agree wholeheartedly.

May 2, 2006 - 13:52
Iqbal:

It would have been very difficult to get critical mass if Drupal was written in Java.

Dries, I 100% agree with you. One of the most important things that make Drupal success is the programming language used to build it (PHP).

I'm not talking about technical issue. Both PHP and Java are great languages. I'm talking about availability (PHP is widely available at affordable cost). Almost every hosting service has PHP support. It makes Drupal available for everyone.

Dries, thank you for the Drupal. It's a great software. We are going to use it for our server.

May 3, 2006 - 02:36
Khalid:

Rats ... this means the long awaited Java port of Drupal will never happen ... what a disappointment ... ;-)

May 13, 2006 - 21:07
Anonymous:

It would have been very difficult to get critical mass if Drupal was written in Java.

It's not that it would be difficult, it just means that not every Tom, Dick, and Harry that read a book on Java with no education or experience could contribute. I've seen Drupal, and Joomla, and other open source CMS products. In my opinion, there is a lot of garbage code and components out there that no one reviews and so the standard of coding has become a "read-a-tutorial" on PHP and I know what I am doing type of thing. Sql-Injections, form-hacks, they are all over the place with. Anyone can write PHP code (not necessarily good code) but not everyone can write Java code.

June 27, 2008 - 06:34
Daniel Zhou:

Dries, I also agree with you that Drupal should be written in PHP rather than Java. However, I hope Drupal could provide a Java-Drupal library so that people can develop Drupal modules using Java. There are tons of tools written in Java such as Lucene that could make Drupal more powerful.

August 15, 2008 - 19:42
Sebastiano Costa:

In my opinion any programming language has pro and cons and it's stupid to say "this language is better than that one" or "anyone can write code using PHP but only someone can do it in Java" ... bla bla ... Flickr, Facebook, Wikipedia and many other thousands successfully applications have been written in PHP and what is great is the idea behind (the target) not the tool !! So let's do a comparison between the various languages but just to let people decide which one to use (according to their needs) not to say this is the best and this is the worse ! These discussions are for the children !

May 19, 2009 - 23:59
Anonymous:

I think the point is, we all know Java would be better for damn near anything, but no-one has Java.

I pay $5 per month for shared web hosting. If I want to install things like blogging software, it has to be PHP. That's just all there is.

If I wanted Java, I'd have to pay more or go somewhere else. *everywhere* has PHP. There's never any question of it.

Those of you talking about Wikipedia and Facebook etc ...

They probably got started on PHP not because it was the best tool for the job in some theoretical computer science sense, but because they happened to know it. Once they had a quick prototype scratched out, why start over?

Just because PHP *can* do it doesn't mean it's ideal. And even with facebook, PHP is just a front-end language for writing up the look and feel. They don't build their backend in PHP. Not only that but I've heard they even modify mod PHP to optimize it for their system.

July 24, 2009 - 07:41
David Legg:

As a Java developer I look somewhat enviously at the PHP fraternity when it comes to supporting small business sites.

You seem to have lots of ISPs providing PHP ready server platforms at relatively cheap prices. Additionally because of the huge developer base there seems to be reliable software to do just about anything you want.

Java is not that well catered for by ISPs. It needs lots of memory and ISPs are reluctant to provide it in useful quantities without it becoming uneconomic.

You could get round this by renting a small dedicated server or even a virtual dedicated server from an ISP but that isn't practical for customers with small sites. In any case you would then have the problem of how to backup the machine because most ISPs leave it up to you to backup your dedicated servers. Similarly, my experience with virtual dedicated servers shows lots of stoppages due to other clients hogging resources.

July 24, 2009 - 20:05

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

© 1999-2009 Dries Buytaert Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
Drupal is a Registered Trademark of Dries Buytaert.