且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否有类似CoffeeScript for PHP的东西?

更新时间:2023-11-29 07:55:58

简短的回答是否".由于独特的因素融合,CoffeeScript逐渐流行起来.正如Wesley所指出的,JavaScript在浏览器平台上具有垄断地位,而PHP仅在.php文件上具有垄断地位.在您自己的服务器上,如果您不喜欢PHP,则可以仅使用Ruby,Python,Perl或任何多种JVM或.NET语言.

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.

另一个因素是JavaScript的设计有点偶然.它的创建者Brendan Eich被告知使其看起来像Java".但从语义上讲,它与Lisp和Smalltalk有更多共同点.可以说CoffeeScript提供的语法更适合JavaScript的内部工作.

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自身语法的发展因与旧版浏览器保持兼容性的需要而受到严重阻碍. PHP不受任何限制,因为任何将代码从PHP4过渡到PHP5的人都可以证明.如果要使JavaScript成为更好的语言,则需要一个预编译器.如果要使PHP成为更好的语言,请发布对PHP6的功能请求. (在我的原始答案中,我因愚人节的玩笑而堕落,声称是

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. ( 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...)

所有这些都说,拥有像PHP的CoffeeScript这样的语言可能很酷. WordPress的持续成功及其在用户经常无法控制的服务器上的使用证明了PHP作为部署语言的独特地位.将PHP与其他标记语言(例如Haml)一起使用也很困难.也许将另一种标记语言与新鲜的PHP语法结合使用,可能会为人们提供足够有说服力的理由来预编译他们的PHP.

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.