PHP @ 24 April 2008, “6 Comments”

月光博客上写了一篇Java在Web开发语言上败给了PHP,TSS上很早就讨论了,这回在月光博客那里又吵起来了,各说各有理,各有各的瘾,想起从前论坛上一句名言:人是不能被说服的,只有被打服。(哎,跑题了)

好,那又有什么理由说PHP比其它语言好呢,还绝对?

答案是:MM。

MM?是的, 美媚,women, female, , Frauen, fille,girls, chicks… (得,这么写,会被当作spam么?)

Tim Bray在OpenWeb and PHP and Women首先观察到:

there are way more women in the audience.

然后看看留言的解释或者解释,也都很有道理:

PHP being a language that is far better at attracting people without a formal training in programming.

I’d agree with the people who ascribe it to the move from designer to (often unintentional) programmer. I know several women who fit into this category, and unlike the women “programmers” that I know, I don’t know these women *because* they are programmers. These women don’t really think of themselves as programmers — it’s more an unintentional role they fell into in order to get things done.

Okay,标题党骗点结束。其实总结就是:对非程序员科班出身的网页设计师(很多是女性)来说,PHP是最容易迈入网站开发的语言。对已经有了静态网页设计的基础的他们来说,想要进一步实现动态页面,比如显示“早安/晚上好“或者显示时间,只要很简单一句话。接着就可以很快掌握提交的表单的处理,直接使用$_POST和$_GET即可,再下一步就能很快进入数据库操作,也不需要预先了解和加载驱动程序。

用Java呢?恩…我们要先有个类,什么?… 哦 … 让我们从介绍什么是类,等等,你们需要知道什么是面向对象,抽象地说形而上地来说每一个物体都可以看作是一个对象…对象有属性也有动作… ?*%#^%$水克火^&!%火克金&&*#@^法克由!@&~

这点上看,PHP最方便地提供了一个能够不断提供正反馈的学习,实践和进阶的过程, 能够让学习者很快get into the flow,同时也是最接近Web的语言。这能鼓励和吸引许多想要开发动态页面而又不是程序员科班出身的设计师和爱好者们。

为什么最方便呢,因为很普遍,绝大部分的虚拟主机服务提供商都会提供PHP环境,很少提供perl,ruby,java,python的环境(最近google推出的AppEngine算个特殊例子),这是它们的环境特性决定的,这也是PHP的一大优势之处,具体请看:What PHP Deployment Gets Right

至于讨论语言本身的优势和功能,争论哪个语言的代码的结构端庄优雅更出得厅堂入得厨房,咱就不参和了,The Daily WTF上看看,什么语言的都有的。

月光博客还提到一个问题:“而成功的Java网站却寥寥无几,这又是什么原因呢?”,原因很简单,都在吭哧吭哧埋头赚钱呢,全球许许多多的金融业(retail banking, corporate banking, risk management)企业的网站都是用Java实现的,另外,ebay和阿里巴巴也都是用Java。

In Infoworld’s article, Java performance improvements touted quoted:

As your program grows in size, the lack of strong typing basically kills your ability to handle a very large program and so you don’t find the million-line Perl program.

In response, chromatic said:

the reason that there aren’t many million-line Perl programs is that the people who are capable of writing and managing million-line Perl programs have better ways to organize their projects than glomming a million lines of Java into a single shared-everything instance.

My reflection and thoughts:

  1. Interestingly, why the pick on Perl? not Python or Ruby or Lisp-flavoured ones?
  2. s/Perl/PHP/g or s/Perl/Python/g etc. on chromatic’s quote still valid and sound;
  3. Java => Strong typing? Not necessarily always;
  4. IntelliJ IDEA is the only reason I still code in Java, Eclipse? that would be another post;
  5. Vim (together with some bash scripts and esvn) has been my primary “IDE” for projects that involve php, python, bash and javascript;
  6. I have written Perl applications before, and would be very happy to pick it up for my next project if everything else fits (e.g. the team factor);
  7. When would I code in Java? most likely a project that:
    • being “enterprisy”, or
    • I am really interested to learn, explore and apply, e.g. Antlr.