php each替代_为什么选择PHP而非替代品?

php each替代

This article was sponsored by AppDynamics. Thank you for supporting the sponsors who make SitePoint possible!

本文由AppDynamics赞助。 感谢您支持使SitePoint成为可能的赞助商!

It’s a popular question. Why indeed should one pick PHP over one of the alternatives? After all, PHP has often been dismissed as a hacky, unusable and badly designed language. Why would anyone choose it, when starting a project from scratch?

这是一个受欢迎的问题。 为什么确实应该选择PHP而不是其中一种? 毕竟,PHP已经常常 解雇哈克无法使用严重的设计语言。 从头开始一个项目时,为什么有人会选择它?

Instead of listing the reasons why people do choose it (mostly widespread availability), let’s instead focus on why people should choose it. We can’t talk about that, however, without first mentioning why they shouldn’t.

而不是列出为什么人们选择它的原因(主要是普及),让我们转而专注于人们为什么选择它。 但是,我们不能不先谈谈为什么不应该谈论这些。

什么时候不应该选择PHP (When you should NOT choose PHP)

在考虑命令行应用程序时 (When considering command line apps)

If you’re building a command line app, PHP is not the right choice. Sure, there are decent approaches to building CLA with PHP, but it simply isn’t intended for that. PHP is a web language, first and foremost, and a pure command line app is better built in something else. That’s not to say it isn’t possible – but it’s definitely quicker and easier to do it in another language – not to mention more performant. Building CLI apps in PHP lends itself to the metaphors people use when comparing PHP to a double-clawed hammer. It just isn’t a tool that’s intended for it. For example – Python is pre-installed on most *nix distributions, so you have immediate access to it without needing php.ini hackery, and can start working right away.

如果要构建命令行应用程序,则PHP 不是正确的选择。 当然,有使用PHP构建CLA的不错的方法 ,但是它根本不打算这样做。 首先,PHP是一种网络语言,最好在其他内容中构建纯命令行应用程序。 这并不是说不可能 -但是用另一种语言绝对可以更快,更轻松地完成它-更不用说性能更高了。 用PHP构建CLI应用程序很容易让人联想到将PHP与双爪锤进行比较时所使用的隐喻。 它不是专门用于此目的的工具。 例如–大多数* nix发行版上都预安装了Python,因此您无需php.ini黑客就可以立即访问它,并且可以立即开始工作。

何时似乎最简单 (When it seems easiest)

If PHP seems the easiest of the bunch and that’s your sole motivator, your heart is in the wrong place. PHP can get complicated fast, and while the entry path is, admittedly, easier than with other languages, the pro level shares its complexity with alternatives. Doing serious work is similarly difficult in any language.

如果PHP似乎是最简单的方法,并且这是您唯一的动机,那么您的心就在错误的地方。 PHP可以很快变得复杂,并且尽管公认的是,进入路径比其他语言更容易,但专业人士与其他人士共享其复杂性。 用任何语言进行认真的工作也同样困难。

只是因为您的共享托管服务提供商支持 (Just because your shared hosting provider supports it)

If you’re using a shared host, and delight in the fact that it supports PHP (maybe even a not totally archaic version like 5.3), stop. If you’re calling yourself a developer, you should never use shared hosts for anything except the banalities like custom webmail, domain management, or very simple demos. With alternatives such as DigitalOcean offering virtual private servers hosted on SSDs for as little as $5 per month, picking a shared host makes no sense – not when a private instance gives you so much more control. If you’ve got something against DevOps and don’t like setting up your own server (you should really learn to do it, though), many, many cloud hosting providers offer free tiers that are pre-configured for you. Stay away from shared hosts.

如果您使用的是共享主机,并且对它支持PHP(甚至可能不是5.3等完全不古老的版本)感到满意,请停止。 如果你调用自己的开发人员,你应该使用共享主机以外,如自定义Web邮件,域名管理,或非常简单的演示陈腐什么 。 使用DigitalOcean之类的替代方案以每月低至5美元的价格提供在SSD上托管的虚拟专用服务器,选择共享主机毫无意义-私有实例为您提供了更多控制权时,这是没有道理的。 如果您对DevOps有所抵触并且不喜欢设置自己的服务器(不过, 您应该真正学会做这件事 ),那么许多很多云托管提供商都提供了为您预先配置的免费层。 远离共享主机。

计算密集型软件 (Computationally intensive software)

When you expect to be dealing with a lot of math, heavy calculation, statistics and the like, there are better options – especially if the app does mostly this, and little of anything else. In particular, functional languages like Scala or the newcomer Dart will perform much better at this task than PHP, which might require more effort than it’s worth to get it to do what you want. It’s also significantly slower at these tasks than languages specifically designed for them.

当您希望处理大量的数学,繁重的计算,统计工作等等时,有更好的选择-特别是如果应用程序主要执行此操作,而没有其他任何事情。 特别是,像Scala或新来的Dart之类的功能语言在此任务上的性能将比PHP更好, PHP可能需要付出更多的努力才能让它做您想要的事情。 这些任务比专门为它们设计的语言要慢得多。

Sometimes it’s simpler to write a computationally heavy part of the application in a language you’re already involved with in the current app, but more often than not that’s a lazy shortcut. The discomfort of having to install a helper language or VM and build part of the app as a separate application is quite often offset by the long term gains, especially when traffic starts to demand it. There’s a reason Twitter’s back end calculations are all in Scala now even though their frontend is still RoR.

有时,使用您已经在当前应用程序中使用的语言来编写应用程序中计算量很大的部分会更简单,但是通常这不是一个懒惰的捷径。 长期获得的收益常常抵消了必须安装辅助语言或VM并将应用程序的一部分作为单独的应用程序进行构建的不适感,尤其是在流量开始需求时。 尽管Twitter的前端仍然是RoR,现在 Twitter的后端计算全部都在Scala中 是有原因的

PHP高度易学 (PHP is highly learnable)

The problems listed above are problems of inadequate knowledge and experience, and naturally, when someone uses PHP for such a purpose, the end result is suboptimal – adding bad press to PHP’s already tarnished reputation. What PHP is good for, is any web oriented scenario that needs to be developed quickly, and needs to perform really fast.

上面列出的问题是知识和经验不足的问题,自然地,当某人使用PHP达到此目的时,最终结果将不是最理想的-给已经已经失去声誉PHP增加了负面新闻。 PHP的优点是,任何需要快速开发并且需要快速执行的面向Web的方案。

PHP sports an enormous community. True, the vast majority are newbies, but once you weed out the chaff, what remains is a handful of dedicated professionals like Phil Sturgeon, Josh Lockhart, Mike van Riel, Anthony Ferrara and many, many more. A dozen of highly dedicated professionals who admit to PHP’s faults but also work hard on educating the public and fixing these issues can provide a wealth of knowledge. Coupled with excellent resources like SitePoint’s forums, StackOverflow and PTRW, problems encountered in PHP are easily solved, and progress is usually both rapid and highly educational. Unless the questions you ask are downright stupid (and yes, there are stupid questions), the community is non-elitist and always ready to help.

PHP拥有庞大的社区。 的确,绝大多数是新手 ,但是一旦您摆脱了谷歌,剩下的就是像菲尔·斯特金 ( Phil Sturgeon)乔什·洛克哈特 ( Josh Lockhart)迈克·范瑞尔 ( Mike van Riel)安东尼·费拉拉 ( Anthony Ferrara)等许多专业人士。 十二位高度敬业的专业人员,他们承认PHP的错误,但同时也致力于教育公众并解决这些问题,可以提供丰富的知识。 加上SitePoint的论坛StackOverflowPTRW等出色的资源,可以轻松解决PHP中遇到的问题,并且进度通常既快速又具有很高的教育意义。 除非你问的问题是彻头彻尾的愚蠢(是的, 愚蠢的问题),社区非精英和随时准备提供帮助。

The number of open source PHP projects as well as books and courses one can learn from is plentiful, and with patience and guidance one can become highly proficient in the language in a relatively short period of time.

人们可以从中学习大量的开源PHP项目以及书籍和课程 ,并且在耐心和指导下,可以在相对较短的时间内熟练掌握该语言。

消除不良新闻 (Dispelling the bad press)

PHP has matured significantly since the last time people collectively bashed it, and is inheriting more and more modern features from other languages. Prejudice is prevalent, and one should learn to recognize it. As this excellent MailChimp blog post from 2010 says, it’s not the tool, it’s how you use it.

自上次人们集体抨击PHP以来,PHP已经显着成熟,并且正在从其他语言继承越来越多的现代功能 。 偏见很普遍,人们应该学会认识到它。 正如2010年MailChimp上一篇出色的博客文章所述 ,它不是工具,而是您的使用方式。

PHP allows rapid prototyping of all types of applications, and can get you up and running in no time. It’s a fast and robust language that outperforms RoR and Python by a lot in complex web apps, and with the added benefits of projects like HHVM and Phalcon, PHP’s performance is unchallenged in the land of dynamic languages. Typing is coming in both regular PHP and HHVM’s Hack in at least some form, and as giants like Facebook continue to work on it directly, PHP can be taken ever more seriously.

PHP允许对所有类型的应用程序进行快速原型制作,并可以立即使您启动并运行。 它是一种快速而强大的语言,在复杂的Web应用程序中,其性能大大超过RoR和Python,并且具有HHVMPhalcon等项目的额外好处,在动态语言领域,PHP的性能无可争议。 常规PHPHHVM的Hack至少都以某种形式出现输入,并且随着Facebook之类的巨头继续直接对其进行开发,PHP可能会越来越受到重视

Now, before jumping on the bandwagon and yelling “just use NodeJS, it’s teh best!!11” or “MailChimp would have been better off using NodeJS from the start”, please first consider how hacky and fragmented the JavaScript world is in its current form. So much younger than PHP, the frameworks it offers already outnumber PHP’s – a frequent point of ridicule among PHP haters. NodeJS is 5 years old, and its most recent version at the time of this writing is v0.10.25. The developers seem so unsure of it, they refuse to let it go past even 0.1 after five years, let alone venture into 1.x waters. There is also constant disparity between the various solutions, and every single one claims to be “a simpler/better/faster way to do X”. The community is enormous, but horribly fragmented. This Tweet rings particularly true:

现在,在追赶潮流并大喊“仅使用NodeJS,这是最好的!11”或“ MailChimp从一开始就使用NodeJS会更好”之前,请首先考虑一下JavaScript世界在当前的现状如何被破解和支离破碎形成。 它比PHP还要年轻得多,它提供的框架已经超过了PHP,这在PHP仇恨者中经常被嘲笑。 NodeJS已有5年历史,在撰写本文时,其最新版本为v0.10.25。 开发人员似乎对此不太确定,他们拒绝让它在五年后超过0.1,更不用说冒险进入1.x水域了。 各种解决方案之间也存在着持续的差距,每个解决方案都声称是“一种更简单/更好/更快的X方式”。 社区是巨大的,但非常分散。 这条推文特别正确:

Drinking game for web devs: (1) Think of a noun (2) Google “<noun>.js” (3) If a library with that name exists – drink

针对网络开发人员的饮酒游戏:(1)考虑一个名词(2)Google“ <noun> .js”(3)如果存在具有该名称的图书馆–

— Shay Friedman (@ironshay) August 22, 2013

—谢伊·弗里德曼(@ironshay) 2013年8月22日

It’s not my intention to bash other languages – other people can do a much, much, much better job at bashing JS than I can – what I’m trying to point out is the fact that one can nitpick on the downsides of absolutely any language. Just like in life, if you focus only on the bad stuff you’ll never experience the good – PHP’s downsides have been taken care of for the most part by libraries and frameworks, and while one may argue that a “real language” doesn’t need patches or the help of big companies to work, one could counter by asking what exactly Java, NPM or PUB libraries and packages are, if not patches and improvements to the language, adding missing functionality someone else was kind enough to build.

这不是我的意图的bash其他语言-其他人可以做很多很多很多 工作在扑JS比我-我想要指出的是,一个可以在绝对任何语言的缺点鸡蛋里挑骨头。 就像生活中一样,如果您只专注于坏东西,那么您将永远不会体验到好东西– PHP的缺点在很大程度上已由库和框架解决,而有人可能会说“真正的语言”并没有如果不需要补丁或大公司的帮助,则可以通过询问确切的Java,NPM或PUB库和软件包是什么(如果不是补丁和对该语言的改进)来增加缺少的其他人可以构建的功能。

So let’s stop focusing on how bad X language is, and start working on projects that demonstrate the superior nature of our choice. Yes, there are projects out there dragging it down – WordPress is one such project for PHP – but if we persist and build awesomeness with best practices in mind, we can dispel this bad reputation and start rebuilding the PHP world we love.

因此,让我们不再关注X语言的糟糕程度,而开始致力于证明我们所选择的优越性的项目。 是的,有一些项目拖累了它– WordPress是PHP的一个这样的项目–但是,如果我们坚持并牢记最佳实践来建立出色的表现 ,我们可以消除这种不良声誉,并开始重建我们喜欢PHP世界。

结论 (Conclusion)

PHP is an excellent choice for new projects regardless of complexity. The PHP world has been evolving at a truly rapid pace in the past few years, and some revolutionary new features can be put to use even today (refer to the HHVM and Phalcon links above). Far be it from me suggesting PHP should be the only tool in your toolbox – being fluent in more than one language is just as useful in programming languages as it is in natural languages – but it definitely will not hurt to master it. PHP will grant you the ability to go from idea, to prototype, to production in days – and that’s a claim not many languages can make. Recent advances like built-in OpCache and virtual machines like HHVM take the language further, allowing you to greatly reduce your cloud hosting bills, and performance monitors like AppDynamics will let you milk it to its limits.

无论复杂程度如何,PHP都是新项目的绝佳选择。 在过去的几年中,PHP世界一直在以惊人的速度发展,甚至在今天,仍可以使用一些革命性的新功能(请参阅上面的HHVM和Phalcon链接)。 我绝不认为PHP应该是您工具箱中的唯一工具–流利地使用一种以上的语言在编程语言中和在自然语言中一样有用–但绝对掌握它不会有伤害。 PHP将使您能够在几天之内从构思,原型制作到生产,这是许多语言都无法做到的。 内置OpCache和虚拟机(例如HHVM)等最新进展进一步推动了该语言的发展,使您可以大大减少云托管费用,而AppDynamics等性能监视器将使您的应用达到极限。

When considering your next project – don’t ask yourself “Who hates PHP?” or “What will people think?”. These are questions of vanity and insecurity. You think anyone assumed MailChimp, the system that powers millions of emails per day, was built on PHP before they “came clean”? Instead, just do your best and build.

在考虑下一个项目时-不要问自己“谁讨厌PHP?” 或“人们会怎么想?”。 这些是虚荣和不安全的问题。 您认为有人认为MailChimp是每天都可处理数百万封电子邮件的系统,是在PHP变得“干净”之前建立在PHP上的吗? 相反,尽力而为。

翻译自: https://www.sitepoint.com/why-choose-php/

php each替代

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值