Peter Mirus, the CEO of Trinity Consulting, sent me email pointing out the HipHop project from Facebook.  HipHop is a program that converts PHP to C++, then compiles it using gcc.  The idea is that you can write your code in PHP but still get the speed benefits of compiled C++.  It’s an interesting idea and seems compelling at first glance.  If you have code written in PHP that is CPU-bound, why not convert it to a language that allows for much faster execution?

Anyway, HipHop is interesting academically, but I don’t buy some of the arguments they’ve listed.

You keep coding in simpler PHP …

Simpler for whom?  PHP has a veneer of simplicity that appeals to the unwary and disguises lurking complexity waiting to bite you.  A lot of other people have covered PHP’s issues, such as the “==” and “===” operators.  I find C++ to be simpler due to strong typing, explicit variable declaration, etc.  You can prevent yourself from making mistakes.

Companies with large PHP codebases will generally rewrite their complex functionality directly as PHP extensions in either C or C++. Doing so ends up reducing the number of people who are able to work on the company’s entire codebase.

There’s a contradiction here.  They just said that the code is complex.  Anyone who’s capable of understanding and modifying such allegedly complex code probably has the chops to write it in C or C++.  If they can’t handle C/C++, they probably can’t handle truly complex code either.  I’ll grant that fewer people learn C and C++ these days than a decade or two ago, but in my experience most truly good programmers have at least some experience with them.  On the other hand, I’ve never met a really competent programmer who only knew PHP.

I can think of a couple of better arguments:

  1. Using the HipHop approach is more flexible when working with a large code base, because you can easily pick likely sections of code for compilation in order to test performance improvements.
  2. HipHop is potentially faster and less expensive than rewriting those sections in C++.

There are always trade-offs and each situation is unique.  It strikes me that it might be most useful as a testing tool or as a stop-gap measure to improve performance .  On the other hand, it might be that the improvements provided by HipHop are sufficient for Facebook’s needs when compared to the extra expense that rewriting the code in C++ would entail.

In any case, it’s interesting to see an old technique being applied in a new way.  Conversion from one language to another has been used for many reasons in the past, such as bootstrapping new languages.  C++ itself started that way via the Cfront compiler.