HipHop Your Way To PHP

A few days ago facebook released (under opensource) their HipHop for PHP source code transformer. I remember first reading about this from an interview with a facebook employee on reddit. She mentioned that one guy was pretty much rewriting PHP to work on C++, which at the time sounded like they were working on some compiler. The actual product though is different, they basically convert the PHP source into C++ code, and then you can use your compiler of choice (probably g++) to get it up and running. I know something about this area as my final year project at uni I created a code transformer that would take a web script in PHP -> JSP -> ASP and convert it into any of the others. You could basically go in any direction – plus you could add in new modules for other languages that would allow you to transfer between even more. This was far from completion (I had it working for about 50% of common functionality) but I proved that it could be done – I also showed that you could optimize the code quite significantly. I basically added rules that would find common coding patterns and transform these in the AST (abstract syntax tree). Transforming to the new language was relatively easy as the tree was already in a good shape and the transformer knew how to properly express the tree in the most optimized way. The way I see it – HipHop has the opportunity to not only transform but optimize the hell out of the code as well. They say that in practice they are seeing a 50% CPU decrease and much better memory overhead.

I believe that the current version is compatible with PHP5.1 and they are quickly looking to get it compatible with 5.2. There are also some bits that it wont do, such as the rarely used eval() statement and function exists checking – these are things that they cant link to as they don’t know they exist, therefore can’t compile against

I have always liked PHP and have watched it get better and better to the point of it being a very professional tool in the right hands. I still regularly use PHP for my own applications that I need to get out the door quickly and effciently. What makes this interesting to me is that I can also look at it as a tool of choice for applications where I wouldn’t have before used PHP. I will have to play with it a bit and see what it can do. I think it will get more interesting when they get a version that can run on Apache/lighttd etc.

Go and get the code for yourself and check out the video for further information.

For more information on the technical challenges they face scaling Facebook, take a look at this article which goes into a deep enough description.

Apple Is Nuts

I can’t believe that Apple actually has in its iPhone SDK agreement a part that stipulates that you can’t distribute “frameworks”. I can’t possibly see the point of this at all. If I came up with what I thought was a really good framework that helps you to build applications much more stable and faster, wouldn’t this be a good thing to share? Wouldn’t it benefit the entire community? It makes sense now why I haven’t seen any frameworks for the iPhone – I always thought this was a little strange because usually there are ones out within days for other platforms. I just can’t believe how many draconian rules have have stipulated for their SDK, it just goes to show that there really is no better alternative at the moment, because otherwise I can’t fathom why developers would stick around.

I have found out though that it is Ok to share sample code, so you can show people an example app that includes your framework and then let them use it from there. This technically means you are not actually distributing the framework but merely sharing code. This is another example of how dumb the rules are, if you can get away with doing it by calling it something else why not just let people do it properly?

Now I have to mention something about Apple’s app review process. The link provided above is from Joe Hewitts blog – he is a facebook employee who develops their app for the iPhone. It is pretty much agreed that the facebook application is probably the best and most useful free app available on the iPhone (Perhaps best of all apps – who knows). They have just finalised their version 3 application and released it to the store for review – now being an important app you would think that it would have been green lighted pretty fast wouldn’t you? Well nearly two weeks have passed and still nothing. I mean how messed up is that? He has a little rant about the process and I agree with him that the process should be scrapped altogether – go and read the post for the full story. Even techcrunch have been getting angry emails about it all.