Live data from Hacker News

XHP: A New Way to Write PHP (from Facebook)

facebook.com

61–70 of 72 posts

Re: XHP: A New Way to Write PHP (from Facebook)

#61

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 reall…

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

Re: XHP: A New Way to Write PHP (from Facebook)

#62
post #46
post #26

Earlier quoted context omitted.

has anyone gotten this to work on OSX? I get strange errors after I build and add the extension to php.ini LOG: http://pastie.org/817528

Working perfectly for me on OS X snow leopard. It compiled cleanly.

Got it compiled properly now, had to get one of the versions without the lexer/parser files included.

However I'm still getting 'xhp_a' class not found errors with the basic tests from the wiki, the same as the other comments in the sibling thread.

It seems to happen on several platforms so its probably a configuration error somewhere.

Any help would be appreciated.

EDIT: Figured it out. You need to include 'init.php' from 'php-lib' in your php scripts. I copied the directory from the xhp source to my site directory and included them from there.

Re: XHP: A New Way to Write PHP (from Facebook)

#63
Ugh, I dislike this a lot. I'm one of the guys who actually likes PHP, so this may be a bit skewed, but what's wrong with PHP's existing alternate syntax? Most people don't know about it, but it's clean and easy to follow:

  
    display this div
  
    display this div instead
  
This way, you can keep basic logic in your templates (its inevitable and convenient), it's still PHP (there's endforeach, endfor, endwhile, etc.), and this method of templating is very clean.

You can now have a class that sets variables through __set(), loads up a .phtml file, starts output buffering, renders the file with those variables, and then returns it.

You can extend it further to automatically sanitize output variables for XSS and whatnot, cache output, etc. This way, you don't need some overly verbose system like smarty to do what PHP does already. XHP just looks like another smarty: solving a problem that I really don't think exists.

Edit: Ok, I probably shouldn't say I dislike this a lot, I do love seeing Facebook sticking with PHP and ultimately helping it out.

Re: XHP: A New Way to Write PHP (from Facebook)

#64
post #59

Earlier quoted context omitted.

I just installed this on a fresh Linode with a basic Ubuntu 9.10 LAMP stack. It built ok, and the module shows up in phpinfo(), but when I try to run any of the example code, I get an error: Fatal error: Class 'xhp_a' not found in /home/me/public_html/test.php on line 3 Here's the code I tested with: Facebook ; I tried running the code through the xhpize tool, and got the following output: $href,), array('Facebook',)…

I'm having exactly the same problem, same system (Ubuntu Karmic Koala). Prerequisites installed, XHP module installed, it's listed in my phpinfo. For any XHTML tag I include (a, span, ...) the error message says class not included: Fatal error: Class 'xhp_span' not found in ... Any ideas on how to fix would be appreciated. Google and Bing have nothing so far and the module configuration info on the GitHub page is lim…

So, it seems you need to include init.php. Not sure why that doesn't happen automatically.

http://github.com/facebook/xhp/issues#issue/2

Re: XHP: A New Way to Write PHP (from Facebook)

#65

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 reall…

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.

Re: XHP: A New Way to Write PHP (from Facebook)

#66

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 reall…

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.

Re: XHP: A New Way to Write PHP (from Facebook)

#68

Ugh, I dislike this a lot. I'm one of the guys who actually likes PHP, so this may be a bit skewed, but what's wrong with PHP's existing alternate syntax? Most people don't know about it, but it's clean and easy to follow: display this div display this div instead This way, you can keep basic logic in your templates (its inevitable and convenient), it's still PHP (there's endforeach, endfor, endwhile, etc.), and this…

That sort of code can get really messy when you have to put PHP code inside the DIVs.

I think I might like the more concise, readable syntax that XHP offers for interpolating {$variables} (and any PHP code for that matter).

Re: XHP: A New Way to Write PHP (from Facebook)

#69

Earlier quoted context omitted.

That seems to be unrelated to the concern here (as belied by the grandparent citing magic_quotes). XHP (like plain PHP, for that matter) can be used in a way that, for all intents and purposes, separates the concerns of presentation and logic. It's more a matter of convention than constraint.

> separates the concerns of presentation and logic WHAT? The explicit purpose of this is to combine the presentation (HTML) and logic (PHP) layers.

The purpose of a "layer" is not determined by the language it's implemented in, but by what the code actually does. Code that handles nothing but presentation is by definition separate from the business logic, even if the presentation code and business logic are implemented in the same language. It is trivial to implement this architecture with PHP and even easier with XHP.

Re: XHP: A New Way to Write PHP (from Facebook)

#70
Another awesome example of the lengths people will go to compensate for a lack of macros.

I would so much rather see (define table (html-table (map [tr (td _)] rows)))

then

$table = ; foreach($rows as $row) { $table->appendChild({$row}); (assuming this is even possible?) }

Post reply on HN