Hacker News new | past | comments | ask | show | jobs | submit login

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>;



Couple 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?


Filters 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 :)


I'm also very interested in how it is able to escape properly... anybody?


I'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.


It'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.


I fail to see how is this "so much better" than, say, Smarty.


You 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.


I hope you don't mind, but I quoted/linked to this in my post on XHP: 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: