是否有类似CoffeeScript for PHP的东西? [英] Is there anything like CoffeeScript for PHP?

查看:77
本文介绍了是否有类似CoffeeScript for PHP的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP解释器非常常见,但是PHP语法&库不一致麻烦(当然是国际海事组织).我认为一种语言可以编译成PHP,但提供更高级别的功能(例如模块,mixin,列表推导等)和更简单的语法(例如可选的分号,隐含的收益,变量没有美元符号,可选的括号和花括号)等).像这样的东西存在吗?

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?

推荐答案

简短的回答是否".由于独特的因素融合,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.

这篇关于是否有类似CoffeeScript for PHP的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆