PHP和Python目前是世界上最流行的两种Web编程语言,自然都有其各自的优点和缺点。然而,在澳大利亚IDG公司——Techworld Australia的出版商——我们在过去的18个月左右的时间里,正在从PHP迁移到Python。虽然我们还没有为这个决定感到后悔,但如果你觉得从PHP切换至Python是一个简单的决定,就大错特错了。
PHP vs. Python: 语言流行程度
毋庸置疑PHP非常的流行;实际上,它现在是最流行的开源编程语言。PHP开发者和PHP工作都是一抓一大把。现在,在Seek.com.au上,澳大利亚就有大概3790个PHP职位。并且这种需求通常转化为一个巨大的开发者资源池,在需要扩展你的团队时,随时可以从中选出可用的开发者。(And this demand generally translates into a large pool of developers that can be tapped into when you want to expand your team.)
Python从来没有这么流行过。不过,反过来,它没有PHP那么流行有时候也是一种优势。Python开发者可能会更加稀缺,但我发现他们通常素质更高。虽然我确定市场上有一些比较差的Python开发者,但我还没有在面试时遇到过。我很希望PHP开发者也可以这样。
PHP vs. Python: 语言语法
PHP有着非常类似C的语法。任何接触过类C语言的人都可以直观地看到这一点。花括号和分号和你见过的完全一样,感觉很熟悉。在我用PHP开发第一个项目时并没有PHP经历。仅仅花了2个小时,我阅读了一个小教程,发现了我要找的bug并且修复了问题,提交到生产环境。
Python就没有这么容易了。取代了花括号的有意义的空格需要花费一些时间来适应。这个变化需要刚刚开始使用Python的开发者多花一些时间来适应。随着时间的推移,这个缺点就会自行消失,并且,由于Python语法通常极为简单,实际上读起来像伪代码。
PHP vs. Python: 做事情的方法不止一种
许多开发者在面对一个新项目时会倾向于闷着头加班加点的开发,而不仔细思考需求到底是什么。一些语言以提供了尽可能多的解决问题的方法为自豪。而PHP在这一方面并不逊于Perl或者Ruby,它经常为你提供许多种解决问题的方法。Python并不是这样。如果一个任务做起来越来越难,你会发现你做这件事情的方法有问题。这会鼓励初级开发者在一开始就使用正确的方法做事。
PHP经常让人觉得它纯粹是为了创建Web页面而设计的,即使一些人用它完成一些别的任务。默认情况下它的确是嵌套了代码的HTML模板。与之相对,Python是一种独立的(stand on one's own two feet)通用型语言。使用Python进行Web开发涉及选择一种能为你提供所需功能的Web框架。然而,如果你做一些别的开发,并不会让你觉得你背离了这门语言的设计初衷,特别是当你可以使用许多其他通用框架的时候。
PHP vs. Python: Lambda表达式
Lambda表达式一直是Python之于PHP的一项优势。它们非常简单灵活,开发者非常乐于使用。直到最近,PHP只有"create_function"函数,这让人觉得充其量只能是一种hack,并且是一种糟糕的实践(a bad practical joke the rest of the time)。这在PHP的最新版本中已经得到了改变;现在已经得到完全的支持。不过,开发者会使用吗?一些开发者几年以来一直避免使用这个功能。
PHP vs. Python: 调试和分析工具
使用Google搜索Python调试和分析工具总可以找到有用的链接,但是PHP可用的调试和分析工具似乎更多。在这里更加庞大的开发者生态系统是一项优势。话虽如此,相较于PHP,当我在使用Python开发时,需要这种类型工具的概率更低。也许大多数人在使用Python时并不需要这类工具。
PHP vs. Python: 到底是什么样的感觉?
当倾听个人的意见时,似乎PHP占了上风。不过,大多数我认识的两种语言都很擅长的人总是会倾向于使用Python而非PHP。我不知道这是否是由于其简单的语法和更容易编写的和阅读的代码所致,但是当我用Python写一些东西时,我通常可以非常自豪地将它们拿给别人看。而用PHP写的东西就不一定了。这种心态可以用非常简单的语言解释。这两种语言体现出了它们使用者的公司文化。Facebook用PHP。Google用Python。你想要成为哪一种?
纯粹个人层面,我觉得PHP就像是Play-Doh(培乐多彩泥)。你可以用它做出任何想要的东西,但是到头来,它依然是用泥巴做的。
原文链接:http://www.techworld.com.au/article/398573/python_vs_php_choosing_your_next_project_language/
外文原文:
PHP and Python are two of the world's most popular Web programming languages at the moment, and naturally both have distinct advantages and disadvantages. However, at IDG Australia — the publisher of Techworld Australia — we've been working on moving from PHP to Python over the last 18 months or so. Although we're yet to regret this decision, it would be foolish to think that switching from PHP is a simple decision to make.
PHP vs. Python: Language popularity
There is no question that PHP is extremely popular; in fact, it's currently the most popular open source programming language. There are always PHP developers available and there are always PHP jobs around. Right now on Seek.com.au there are some 3790 PHP jobs in Australia. And this demand generally translates into a large pool of developers that can be tapped into when you want to expand your team.
Python has never been that popular. However, counter intuitively, its lack of popularity compared to PHP can sometimes be a strength. Python developers may be somewhat rarer, but I've found they are often of much higher quality. While I'm sure there are some bad Python developers out there in the market, I have never had a job interview with one of them. I would love to be able to say the same thing about PHP developers.
PHP vs. Python: Language syntax
PHP has a very C-like syntax. Anyone who has been exposed to a C-like language gets it straight away. Curly braces and semi-colons work exactly as you'd expect and it feels familiar. I had no PHP experience when I got my first project based on the language. Barely two hours later I had read a small tutorial, found the bug I was looking for and a fix for my problem was being pushed into production.
Python isn't that easy. Making white space significant instead of using curly braces requires some adjustment to how you think about your code. This change will slow down people who have just switched to Python. With time this disadvantage goes away, however, as the Python syntax is usually extremely simple and in fact reads like pseudo-code.
PHP vs. Python: There's more than one way to do it
Many programmers when faced by a new project will tend to run ahead and code up a solution before thinking about what's required. Some languages pride themselves on offering as many ways as possible to solve problems. While PHP isn't as bad as Perl or Ruby in this respect, it will often offer many methods for you to do something. Python is not like that. If a task gets harder and harder to do, you know that you're going about it the wrong way. This will encourage junior developers to do things right the first time around.
PHP vs. Python: Web programming
PHP often feels like it's designed purely for creating Web pages, even if some people use it for other tasks. By default it's really an HTML template with code inserted in. Python, on the other hand, stands on its own two feet as a general purpose language. Programming for the web in Python involves choosing one of the web framework that gives you the functionality you want. If you're coding something different, however, it doesn't feel like you are working against the purpose of the language, specially as you can often use other general-purpose frameworks.
PHP vs. Python: Lambdas
Lambdas have long been an advantage of Python over PHP. They are so simple to create and flow so freely within the language that developers will want to use them when they are the right tool for the job. Until recently PHP only had the "create_function" function, which felt like a hack at best and a bad practical joke the rest of the time. This has changed in the latest version of PHP; there is now closure support. Will developers switch over, however? Some developers have now been avoiding this for years.
PHP vs. Python: Debugging and profiling tools
There are always promising links when you look for Python debugging and profiling tools using Google, but there always seem to be more available for PHP. The bigger developer ecosystem is an advantage here. That being said, I find myself reaching for this type of tool substantially less often when I'm coding with Python compared to in PHP. Maybe most people just don't need these kinds of tools when they are working with Python.
PHP vs. Python: But what does it feel like?
When listing individual reasons, it may seem like PHP has the upper hand. However, most people that I know that are comfortable in both languages will almost always choose to work in Python rather than in PHP. I don't know whether this is due to the simpler syntax and easier to write and understand code, but when I write something in Python, it's usually something I'm proud of that I want to show others. I can never say the same about things I write in PHP. This frame of mind can be explained quite simply. These two languages show up in the company cultures of those who use them. Facebook is in PHP. Google is in Python. Who do you want to be?
On a purely personal level, I'm left with the overriding feeling that PHP is like Play-Doh. You can make anything you want out of it, but at the end of the day it's still made out of Play-Doh.
Pascal Hakim is the director of IT and Development at IDG Australia.
本文链接:http://bookshadow.com/weblog/2014/12/11/python-vs-php-choosing-your-next-project-language/
请尊重作者的劳动成果,转载请注明出处!书影博客保留对文章的所有权利。