Facebook and PHP

There is a common mistake about "If everybody use it, so I also have to use it - millions of people can't be wrong". Apparently, they can, and huge codebase, support and knowledge mean nothing, otherwise we would still use Fortran, Cobol, Basic and other almost died monsters.

Also there is an another common mistake about "If big corporation use it, I also have to use it". It's very doubtful, almost always decision are made in hurry and/or by wrong people and/or without serious consideration. And after some period of time, it's difficult to nullify previous decision because it would require huge efforts. Good example - Facebook.

Let me quote the presentation HipHop for PHP Tech Tasting:
PHP is problematic for Facebook:
  • High CPU usage
  • High memory usage
  • Reuse of PHP logic in other systems
  • Extensions are hard to write for most PHP developers
But huge codebase, strange affection towards PHP (in what universe "loose typing and universal array" are good things? better to ask thousands of programmers who spent millions of hours trying to debug anomalies caused by it) and requirement to "move fast" didn't allow Facebook team to move away from PHP. But they found a good solution - they created a HipHop transformer:
HipHop transforms your PHP source code into highly optimized C++ and then compiles it with g++ to build binary files. You keep coding in simpler PHP, then HipHop executes your source code in a semantically equivalent manner and sacrifices some rarely used features – such as eval() – in exchange for improved performance.
I'd like to notice that during the transformation they change loose typing to strong typing (C++ is a strong typed language, type tricks are not allowed), and that only helps them. Also avoiding dangerous techniques like eval() also can be only plus for them.

So, let me sum up. Don't make rash decision, analyze the situation and all variants, don't be blinded by others popularity. Two words - "be smart" :-) It's obvious, but sometimes we forget it.

P.S. To understand Facebook development more clearly, let me list some other Facebook projects on Github:

  • Tornado (Python) - an open source version of the scalable, non-blocking web server and tools that power FriendFeed;
  • pfff (OCaml) - API to write static analysis, dynamic analysis, code visualizations, code navigations, or style-preserving source-to-source transformations such as refactorings on source code;
  • Scribe (C++)  - a server for aggregating log data streamed in real time from a large number of servers. It is designed to be scalable, extensible without client-side modification, and robust to failure of the network or any specific machine.
  • Cassandra (Java) - a distributed storage system for managing structured data while providing reliability at a massive scale. Now developed by Apache commiters and other contributors: http://cassandra.apache.org/
Also there is a good review of the software behind Facebook.


Popular posts from this blog

DIY: Business cards in LaTeX

Python vs JS vs PHP for embedded systems

Shellcode detection using libemu