3 ms·
XHP rocks so fucking hard, it isn't even funny. It is just so much better than alternatives. IMHO, It is the only PHP tool I use at facebook that is better tha
by ivankirigin 17y ago
XHP rocks so fucking hard, it isn't even funny. It is just so much better than alternatives.
IMHO, It is the only PHP tool I use at facebook that is better than alternatives in other languages. I'm looking at you, django templates!
The notation perfectly represents the objects, with no cruft associated with object oriented programming. That is really rare. You could argue that the markup syntax is cruft, but it really helps code readability to have two types of syntax, for code and for markup.
$b = <span>quotes and variables</span>;
$a = <div>omg, I can't "believe" how easy these {$b} are</div>;
- nostrademons 17y agoCouple questions: 1. How is this different from Django filters? Is it that the default is HTML escaping instead of having to specify the escaping with each template variable? 2. How does it handle different escaping contexts? For example, text in html attributes needs to be escaped differently from text in the body of the document. Text in URLs or JavaScript has to be escaped differently still, and often times you have to combine these escapings (eg. a JavaScript onClick attribute). Is XHP smart enough to recognize these different contexts and do the right thing, or do you need to fall back to some manual mechanism?
- ivankirigin 17y agoFilters are tags in django templates that live in .html files with a bit of logic in a bespoke mini language. XHP for python would be something like this. def view_foo( request ): baz = "roger, roger" return render_foo( baz ) def render_foo( name ): return <html><head></head><body>hi, {name}</body></html> The most glaring difference is that instead of template logic and keywords, you can use python. You definitely want to sequester rendering from the rest of your view, but I see little benefit to django templates. Missing from this code sample is some django middleware which renders a proper HttpResponse() from the XHP return. I don't know well enough to answer about escaping. Check out the framework, and try it for yourself :)
- drusenko 17y agoI'm also very interested in how it is able to escape properly... anybody?
- cmelbye 17y agoI've skimmed through the docs. Each tag that you can use is a PHP class. It knows exactly which attributes it can take and it can do some validations on the attribute values. I'd assume that it knows when there's supposed to be JS in an attribute value and when there's supposed to be text.
- jolie 17y agoI hope you don't mind, but I quoted/linked to this in my post on XHP: http://www.readwriteweb.com/archives/xhp_more_php_enhancement_from_facebook.php http://www.readwriteweb.com/archives/xhp_more_php_enhancemen... I really liked what you had to say! Please let me know if you want me to remove the quotation or change the links around it. I'm jolie@readwriteweb.com.
- rimantas 17y agoI fail to see how is this "so much better" than, say, Smarty.
- wendroid 17y agoIt's turd polish, that doesn't make anything shiny. If your code looks anything like that, or the examples on the Facebook page, you're doing it wrong.
- phatbyte 17y agoYou clearly don't have any idea how django template engine works lol. How can someone even compare this with django, beats me. But Hey, whatever works for you.