PHP has always been poorly designed and poorly stewarded, but it’s appealing to developers because it’s easy to learn (and tons of programmers already know it, so it’s easy to hire for), it’s everywhere and runs on anything, it’s very fast, and it’s very simple to host and maintain server-side. In short, it’s extremely practical.
PHP isn’t a great language, but it is a good language. Most non-PHP developers judge the entire language by bad code snippets “written” (mostly copied and pasted) by amateurs for PHP 4 and posted on Expert Sexchange in 2002, but that’s really not fair: it’s just as possible to write good, well-structured code in PHP as in most other languages, and it became a much better and more capable language in the 5.x series. There are many bad PHP coders and a lot of bad PHP code out there simply because it’s such an easy language for beginners and has been so popular for so long.1
Facebook’s HHVM is one of the best things that has ever happened to PHP. Facebook uses a ton of PHP, and they stand to gain a lot if they can make it faster, so they wrote their own runtime that’s much faster than the official one. This is exactly what the PHP world needed: making its already-fast performance many times faster (amplifying one of PHP’s biggest advantages over other common web languages), providing much-needed competition to Zend, and offering a contingency plan if PHP’s core maintainers ever do something really dumb to the language (which they often attempt to). I’ve already optimized my in-house framework for HHVM and plan to deploy it for testing on Overcast’s server shortly.
Yesterday, Facebook announced Hack, a new language that also runs on HHVM. It’s like a “PHP++” — it adds optional static typing, generics, and a bunch of other enhancements and conveniences to PHP.
Unlike HHVM, adopting Hack is a huge risk. HHVM was great because you could switch to it and switch away from it freely, with almost no effort (especially to switch away). You were still writing PHP. But once you convert a file to Hack and use any of its new features, it’s no longer valid PHP, so you must always use Hack and HHVM from that point forward (or undertake an expensive rewrite).
You’re effectively writing in a new language, albeit with a much smaller learning curve than other language switches since you already know most of the syntax and API. But because Hack isn’t PHP, some of PHP’s biggest advantages — ubiquity, maturity, stability — don’t apply.
Hack is also vulnerable and politically unstable. It’s developed and supported exclusively by one huge web company, and they may decide to deprecate and replace it in a few years2 as their technical needs change or its core engineers move on to new projects.
Since Facebook is migrating its own code to Hack, pure PHP will become a less-tested second-class citizen on HHVM. This could devalue HHVM to the outside world, throwing away the benefits it’s bringing to PHP programmers everywhere. The closeness of the two languages will probably prevent this from becoming a significant problem, but it’s a problem nonetheless.
While I’m mostly glad to see Hack, I’m not going to start writing in it yet. I’m keeping an eye on it, but I don’t want to build a codebase on it until (and unless) it becomes more popular and stable.
Everyone thought all Rails code was inherently amazing in 2006, but that’s because it was very new and was therefore being used mostly by good, experienced programmers. But look around today, with Rails about 8 years old, and there’s a lot of crap out there written in it, too. PHP has been extremely popular for almost twice as long.
Rails’ initial appeal had little to do with the Ruby language: its primary innovation was bringing the modern MVC framework and structure to web apps, rather than having a directory of PHP files sloppily mixing layout with logic. It was a better structure than what most PHP programmers were doing in 2006, but that structure was quickly copied by good PHP programmers and frameworks. There was nothing about the language that made it impossible to use PHP 5 the same way, especially since PHP 5.3 added closures and late static binding in 2009. ↩