O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Language Selection As Architecture

Problem

I hear Ruby on Rails is the best thing since Java, which was the best thing since Perl, which was once a great thing but is now a confusing thing, which is similar to but the reverse of PHP, which was a confusing thing but is becoming great. And then there’s JavaScript, which isn’t Java at all and used to be the bane of everyone’s existence but has come back as the golden child thanks to a household cleaner named Ajax. I’m confused. What should I use to build my app?

Solution

All languages are tools that ultimately can be used to achieve the same goal. Some languages are better at certain tasks, and others dominate different jobs. A paragraph like the question you just asked is sure to upset pretty much anyone with a language preference, which is the very nature of a “religious” war.

This question is, in a sense, like asking whether you should use only a hammer, screwdriver, or monkey wrench to build your house. Always use the right tool for the right job, and always remember to measure twice and cut once.

Discussion

At the risk of wandering innocently into the middle of said religious war, I recommend building Facebook applications using PHP 5. A number of different Client Libraries are available thanks to a very active developer community, but there is only one true ring, and it is known as PHP. You can choose to build your app on one of the other Libraries—and you probably should if you have, for example, an entire .NET stack or have spent the last 10 years becoming a Supreme Perl Monger—but keep in mind that those Libraries get updated after the official one and therefore run the risk of not having access to new features and of breaking when Facebook changes core pieces of Platform.

That said, if you’re following the architecture recommended in Architecting for the Future: Open Web Apps, you can use a combination of different languages by adding a compatibility layer of web services, written in the best language for each frontend, which communicate to your shared backend through a standard data protocol like XML (see Figure 4-6).

Architecture with multiple languages

Figure 4-6. Architecture with multiple languages

Facebook actually uses a mixed language environment, and it is a big fan of the right-tool-for-the-right-job approach. The Facebook team built a framework called Thrift, which they use to do easy cross-language development, and which they have generously made available to the community at large as part of their Open Source Projects initiative (http://developers.facebook.com/opensource.php/). Mark Slee, one of the developers behind Thrift, has contributed a recipe explaining how you can make use of it in your own applications (see Cross-Language Development with Facebook Thrift).

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required