retrodrone retrodrone - 1 year ago 87
PHP Question

Is there anything like CoffeeScript for PHP?

PHP interpreters are very common, but the PHP syntax & libraries are inconsistent & cumbersome (IMO, of course). I think a language that compiles into PHP but provides higher level level features (like, modules, mixins, list comprehensions, etc...) and easier syntax (like optional semicolons, implied returns, no dollar sign for variables, optional brackets and braces, etc...) would be valuable. Does anything like this exist?

Answer Source

The short answer is "no." CoffeeScript rose to popularity because of a unique confluence of factors. For one, as Wesley points out, JavaScript has a monopoly on the browser platform, while PHP only has a monopoly on .php files. On your own servers, if you don't like PHP, you can just use Ruby, Python, Perl, or any of the myriad JVM or .NET languages.

Another factor is that JavaScript's design was something of an accident. Its creator, Brendan Eich, was told to "make it look like Java"; but semantically, it has more in common with Lisp and Smalltalk. CoffeeScript arguably provides a syntax that's a better fit with JavaScript's inner workings.

JavaScript's own syntactic evolution is severely hindered by the need to maintain compatibility with older browsers. PHP suffers no such limitations, as anyone who's transitioned their code from PHP4 to PHP5 can attest. If you want to make JavaScript a better language, you need a precompiler. If you want to make PHP a better language, post a feature request for PHP6. (Edit: In my original answer, I fell for an April Fool's joke claiming that PHP6 had been released in 2010. Obviously I'm not a PHP guy...)

All of that said, it could be cool to have a language that's like CoffeeScript for PHP. The ongoing success of WordPress, and its use on servers that users often have little control over, attests to PHP's unique place as a deployed language. It's also difficult to use PHP with alternative markup languages like Haml. Perhaps an alternative markup language combined with a fresh PHP syntax could produce a compelling enough reason for people to precompile their PHP.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download