转载一个文章 “Python vs. PHP”

Posted on 30th March 2005 by Nio in 程序人生

PHP Everywhere 贴出一篇《Python never had a chance against PHP》的文章,这并不是在对 Python 进行挑衅,而是较为客观地对 PHP 和 Python 进行分析,认为在 Web 应用方面,Python 比不上 PHP:

Python is not a template language, in the sense that you cannot mix code and html easily. PHP is a wonderfully flexible in this respect.

Python is a so-so string processing language. One reason being it treats strings as immutable. PHP has much better string processing facilities: embedded "$var in strings", mutable strings, auto-conversion of other data types to strings, output buffering, etc.

PHP's documentation is cleaner and much easier to understand than Python's. Probably because PHP is a much simpler language.

PHP has tighter integration of a lot of web related stuff. For example, HTTP and SERVER variables.

对于各种语言,我的观点从来都是:存在即是合理的,每个语言都有其应用的空间。就对于 Python 而言,在 Web 方面不如 PHP,但其在通用编程方面功能却要比 PHP 强大得多。而现在流行 Web 编程,所以 PHP 这方面的优势也就决定了增长势头要比 Python 猛得多。

关于此文章的评论也很值得一看。I'll certainly concede that PHP has some important advantages over Python, especially in terms of deployment, isolation, and the ease of starting projects. But I can't agree with much of these particular reasons.

* Templating language: this is true, though you can template perfectly well in Python ― there exist PHP-like systems, as well as templating languages implemented on top of Python. Python itself isn't a templating language so there's no single convention. Of course, even PHP has things like Smarty.

* Python is way, way, WAY better at handling strings compared to PHP. This is the thing that has always driven me crazy in PHP. The $'s are nice ― except for the quoting rules so that $'s aren't interpreted in single quoted strings. That drives me nuts. Python does very good auto-conversion in interpolated strings (%s), and explicit conversion is easy enough. Python also has lots of techniques for buffering ― the specific pattern that PHP uses isn't common, but it's easy to do anyway (StringIO). Python has a concise and fast set of string methods, it has decent regular expression support (more convenient than PHP's at least), and it has really good unicode support. Oh, and NO MAGIC QUOTING. Quoting bugs don't come up that often in Python.

* I don't know what to say about the documentation. I like php.net's comments. I find the original documentation quite poor, and obviously the structure of the language is non-existant, lacking namespaces, modules, classes for most (all?) core types, and other basic organization. Also, most of the Python standard library is implemented in Python, and the source is readable. But it's not an uncommon complaint, so apparently it's something that bothers people.

* Don't good PHP programmers avoid the HTTP and SERVER variables? (register globals or whatever it is) If you just mean a global variable with those values from the request ($_POST?), that's easy in Python, and some frameworks use that. Python works with markup, like HTML and XML, better than PHP ― that's the kind of thing I'd think of if I was thinking about web integration.

� Ian BickingPlease don't forget:

* Smarty is just a rework of PHP itself - its a templating language written in a language already capable of templating. A pointless project from the start, in my opinion, which increases the workload, development time, execution time, and adds an aditional layer where issues can occur.

* Single quotes are there for a reason - so that we don't have to escape special characters all the time. I use single quotes and concattenation for everything, which can be a major speed increase when working with strings in PHP. We can, and its recommended to, turn Magic Quoting off.

* PHP has released a version of its original documentation which incorporates the comments from the website. I find this very useful. However, it only works on windows.

* As for the structure of PHP… IMHO it makes it easy for people to get started, and then (if they wish, as I did) to move to more structured development techniques, then on to other lanugages. I've recently started to look at Python as my next development language, after PHP, JavaScript (Client-side), XSL, and XQuery. Without PHP's quick learning curve, I don't think I'd have ever gotted started.

* No, we don't avoid the global variables, we just avoid the depricated ones. $HTTP_SERVER_VARS and the like. Register globals is the method that allows any parameter passed to a script in GET or POST format to be instantly accessible within the script. This is a serious security threat, and therefore we access them now through the $_POST and $_GET arrays. Variables such as $_SERVER allow us access to information which is passed around via http headers from client to server. Very handy.

* With the advent of PHP5, working with HTML and XML has become very easy. We can now quickly populate objects with a DOM, and modify elements/nodes and attributes with ease. We can also perform XPath queries easily on them. XSLT has been around for a while too, so a lot on the time things can be collected and translated without PHP doing much work.

PHP has its place, and in the future I hope that it will grow to incorporate some of the benefits of other languages, such as persistance. But for the moment while developing for the web, I'll first look at whether PHP can provide a solution before considering other platforms.


转载:Facebook 架构学习

| Twitter | Del.icio.us | Comments (5) |  | Edit

留言评论 | Comments (5)

NewsFeed 的架构对SNS类型的网站有很好的借鉴意义,这里的数据传输基本可以算是三角传输的实现,aggregators的作用非常大,完成了数据的合并排序。





(1)后端用erlang --- 难点erlang比较难上手。。。

(2)后端用nginx + php --- 不知nginx能否承受像如webim的这种comet的大并发数。。



用最熟悉的东西去做。 之前做评估,而不是靠想象





Gentoo下安装Oracle 11g

折腾了一个下午,终于在gentoo下安装成功。安装过程都是记忆中仅存的,系统环境为去年某时装的gentoo 2007.0 amd64,由于gentoo下没有安装桌面环境,所以在一台windows的机器上装了xming,设置xming的启动参数增加-ac,否则gentoo在设置了DISPLAY后会提示connect refuse的信息。


1: 增加用户和组

groupadd -g 10000 dba

groupadd -g 10001 oinstall

useradd -u 10000 -g dba -G dba,oinstall -s /sbin/bash -m -d /oracle oracle


emerge sun-jdk libaio logger libstdc++-v3 app-emulation/emul-linux-x86-baselibs app-emulation/emul-linux-x86-xlibs


export ORACLE_BASE=/oracle
export ORACLE_PATH=$ORACLE_BASE/common/oracle/sql:.:$ORACLE_HOME/rdbms/admin
export ORACLE_SID=orcl1
export PATH=$ORACLE_HOME/bin:$ORA_CRS_HOME/bin:${PATH}:$HOME/bin
export PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH=${PATH}:$ORACLE_BASE/common/oracle/bin
export ORACLE_TERM=xterm
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS10=$ORACLE_HOME/nls/data
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib:$ORACLE_HOME/oracm/lib:$ORACLE_HOME/lib
export THREADS_FLAG=native
export TEMP=/tmp
export TMPDIR=/tmp
export NLS_LANG=american_america.WE8ISO8859P1
export DISPLAY=
export EDITOR=vi


    kernel.shmall = 2097152   kernel.shmmax = 2147483648     kernel.shmmni = 4096   kernel.sem = 250 32000 100 128     fs.file-max = 65536   net.ipv4.ip_local_port_range = 1024 65000     net.core.rmem_default=262144   net.core.wmem_default=262144     net.core.rmem_max=262144   net.core.wmem_max=262144


su – oracle

cd database



  Error 1:     undefined reference to __pthread_unwind@GLIBC_PRIVATE 解决方法:     编辑$ORACLE_HOME/lib/sysliblist,在-ldl -lm -lpthread -lnsl -lirc -lipgo后加-lrt  Error 2:     cannot find -lagtsh 解决方法:     将database/stage/Components/oracle.rdbms.util/文件解压缩,copy 32位的libagtsh.so.1.0文件到$ORACLE_HOME/lib32目录中  Error 3:     skipping incompatible /usr/lib64/libpthread_nonshared.a when searching for /usr/lib64/libpthread_nonshared.a 解决方法:     修改$ORACLE_HOME/bin/genclntsh:        [ "$1" = "lib32" ] && ULIB="lib32" && LOOP="DONE" && CF=-m32 && USRLIB32=-L/usr/lib32        LD="gcc ${CF} -shared -Wl,-relax ${STUBS} ${USRLIB32} -L${OLIB}"     修改$ORACLE_HOME/bin/genagtsh:        if [ $1 != "-32" ]; then        LIB_NAME=$1 # Library name        LIB_VER=$2 # Library version number        LIB=lib        NON64_LDOPT=        USRLIB32=        else        LIB_NAME=$2 # Library name        LIB_VER=$3 # Library version number        LIB=lib32        LOOP="done"        NON64_LDOPT="-m32"        USRLIB32=-L/usr/lib32        fi         LD="gcc ${NON64_LDOPT} -shared ${USRLIB32} -L${ORACLE_HOME}/${LIB} -L${ORACLE_HOME}/${LIB}/stubs"    修改$ORACLE_HOME/ctx/lib/env_ctx.mk:        LDFLAGS32=$(AMD32FLAGS) -o $@ -L/usr/lib32 $(LDPATHFLAG)$(PRODLIBHOME32) $(LDPATHFLAG)$(LIBHOME32) $(LDPATHFLAG)$(LIBHOME32)stubs/    修改$ORACLE_HOME/rdbms/lib/env_rdbms.mk:        REDEFINES32=LIBDIR=lib32 LDFLAGS='-m32 -o $$@ -L/usr/lib32 $$(LDPATHFLAG)$$(PRODLIBHOME) $$(LDPATHFLAG)$$(LIBHOME) $$(LDPATHFLAG)$$(LIBHOME)stubs/'  Error 4:     cannot find -lclntsh 解决方法:     下载oracle client 32bit的zip包,解压缩,然后将client/stage/Components/oracle.rdbms.ic/文件解压缩,copy 32位的libclntsh.so.11.1文件到$ORACLE_HOME/lib32目录中  Error 5:     gcc: /usr/lib64/libstdc++.so.6: No such file or directory 解决方法:     cd /usr/lib64/ ; ln -s libstdc++.so.5 libstdc++.so.6