6 ms·
"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)" I'm a Facebook engineer who works o
by kmavm 15y ago
"(And strictly speaking, Facebook isn’t written in PHP; it’s written in a C++ macro language with a striking resemblance.)"
I'm a Facebook engineer who works on the HipHop compiler and HipHop virtual machine. It's in PHP, absolutely full stop.
It's amazing how much the fact that g++ is involved somewhere in the toolchain confuses people in this matter. C++ is just an intermediate representation; the source language really is warts-and-all PHP.
- jacques_chester 15y agoHe's using poetic license, if that's not obvious.
- kmavm 15y ago"Prosaic license"? If the essay was written in iambic pentameter, it certainly escaped me. Anyway, "C++ macro language with striking similarities" has a pretty precise technical meaning, which sane, literate people might actually mistake.
- ComputerGuru 15y ago"poetic license" isn't the same as "poetic." From the free dictionary: poetic license n. The liberty taken by an artist or a writer in deviating from conventional form or fact to achieve a desired effect.
- deleted 15y ago[deleted]
- eevee 15y agoInteresting. Redacted, with apologies.
- jacques_chester 15y agoOh. I guess you weren't using poetic license.
- eevee 15y agoI was trying, but it appears to have been a bit too poetic.
- pdmccormick 15y agoPHP as a language is, at present, defined by the behaviour of the canonical PHP.net implementation. Change the implementation, and de facto you've changed the language; Perl 5 is similar in this respect. A claim that an alternate implementation or tool chain supports _that_ very same language is a curious statement. It is an alternate implementation, and surely it must differ behaviourally, even if only by having unique bugs. IIRC Facebook engineers must use HipHop for all their development, with PHP.net's php being now incompatible (hence the push to speed up the interpreter.) Wouldn't that make the language-supported-by-HipHop a PHP flavoured superset at the very least?
- kmavm 15y agoWhich canonical PHP.net implementation? They differ across minor revisions, in intentional and unintentional ways. In the absence of a standard, saying what is and is not PHP is necessarily a practical matter: useful PHP implementations are those that run non-trivial PHP applications. HipHop qualifies. FB's dependence on HipHop is because of backwards-compatible extensions to the language (like yield, e.g.). These extensions don't prevent HipHop from running normal PHP programs, though our use of them does prevent us from using Zend. The extensions are under flags that default off, if you don't want to use them.
- eevee 15y agoThis was the same argument I was having in my head, and in the end I couldn't draw a clear enough line between something like Jython and something like HipHop.
- _sh 15y agoDoes warts-and-all PHP include that eval wart, or is it more like most-warts-and-a-subset-of-all PHP? Not snarky, just curious if there was something I missed.
- kmavm 15y agoThe HipHop compiler will optimize much, much more effectively if non-trivial eval() is disallowed, as it is in FB's production code. Obviously, since it's an ahead-of-time system, complex code in eval() will run slowly. The HipHop virtual machine is perfectly happy with eval().
- fragsworth 15y agoWhat is the problem with eval? Even Python lets you do that. There are legitimate uses for it.
- pbiggar 15y agoIt is difficult to statically compile code that uses eval, since it could be doing anything at run-time.
- dalore 15y agoIt easier to write an optimizer if you don't use eval since the eval code needs an interpreter.
- eru 15y ago> [...] since the eval code needs an interpreter. Or a compiler at run-time.
- colanderman 15y agoName one. I can't think of any that aren't better served by other constructs. eval does have one huge, honking problem though: it permits text to be interpreted as code. This is just asking for code injection attacks. If you really need incremental/multi-stage evaluation, see MetaOCaml (http://www.metaocaml.org/ http://www.metaocaml.org/) for the proper way to do it (without exposing yourself to injection vulnerabilities). It's a consequence of PHP's by-the-seat-of-your-pants approach to language design that the PHP devs settled for eval instead.
- randomdata 15y agoI find it to be an interesting philosophical question about what defines a language. If you write code in Java, but compile it to native format (using gcj, for instance) instead of using the JVM, is it still Java? In doing so, you lose what is probably the language's biggest selling feature. Or, perhaps less relevant now, but I remember the days where people would go on about how Ruby didn't support native threads. Except there were interpreters that did use native threads with the exact same Ruby code. Was Ruby code running under one of those other interpreters still a Ruby application? PHP too comes with expectations about the environment, like how it integrates into the web server stack, which if not met, is it still PHP? I'm not really familiar with HipHop, but, for instance, if you have to compile your code before deployment, you're not meeting one very prominent expectation of PHP: The ability to edit the code in-place on the live server (best practices notwithstanding). So, what does define a language? Is a language just the syntax? Standard library APIs? Standard library behaviour (see Ruby example)? Runtime environment? I'm not sure you will find a generally accepted answer.
- pbiggar 15y agoThere used to be a generally accepted answer, which is that there were languages, and there were implementations of languages, and that those were separate things. C++ was not g++, and vice versa. But the lines got very much blurred by the rise of scripting languages, in which - typically - the language was defined by the implementation. So for a few years there, it really was difficult to tell whether this was Python or CPython. Fortunately, nearly all the languages to which this applies matured and got new implementations. Rubyists often to refer to the C ruby implementation as MRI (Matz' ruby interpreter), and there are lots of different Ruby implementations now. Python went out of its way to document behaviour which was specific to CPython, and put a lot of weight behind Unladen Swallow and Pypy. But your Java example is bonkers. Compiling Java to native is still Java, its just not JVM. Compiling clojure to JVM is just JVM. The language feature is not the language. In Java's case, the language is specified, the VM is specified, the bytecode is specified. There really should be no ambiguity at all there.
- pjmlp 15y agoThe problem is that most people lack the proper compiler development background when discussing languages. Most people without a proper CS background mix the language with the implementation. A language is defined by: - syntax - semantics - libraries Everything above can be made available as: - bytecode interpreter - text parser based interpreter (like the earlier BASICs) - compiler - JIT That is why it is absurd to discuss language A vs language B in regard to implementations, because any language can have all types of implementations. It is always a matter of cost/benefit which type of implementation is used as default for a given language.
- enneff 15y agoDo your engineers use the PHP interpreter in development (for rapid prototyping) and HipHop-compiled PHP in production (for speed)?
- qixxiq 15y agoThey have an interpreted version of HipHop as well. Can't use the PHP interpreter due to a couple added features (python-esque yield is the only one I know of)
- HerroRygar 15y agoI seem to remember reading that Facebook was using XHP, which allowed XML literals. That would certainly be an improvement over "warts-and-all PHP", in my opinion. Of course, I'll trust what an actual engineer from Facebook is saying over some article that I can't even cite. Is this not the case?
- nbm 15y agoXHP is orthogonal to HipHop, since XHP is available as a module for Zend PHP - https://github.com/facebook/xhp https://github.com/facebook/xhp.
- zerostar07 15y agoSomehow i find that very comforting that such a heavily trafficked site relies on it. I 'm a happy PHP programmer for at least 10 years. Not overly happy about it but in the end not disappointed about it. I haven't found an overall better alternative tool for the domain yet.
- bascule 15y ago"It's in PHP, absolutely full stop" Well, you're the authority, but is that really a fair assessment? Has HipHop diverged from PHP enough to really still be considered PHP?
- rictic 15y agoHm, I'll admit I've spread a bit of misinformation on that matter myself, thanks for the correction. The source for my confusion (and I suspect others as well) was some comments around the time hip hop was made public that it basically wasn't worth using unless you were willing to put in a significant effort to write your php according to some strict guidelines. That made me peg it as something akin to pypy's rpython.