Tuesday, November 20, 2007

Finally! The difference between PHP, ASP and other scripting languages.

PHP

PHP uses a blend of interpretation and compilation in order to provide the best mix of performance and flexibility to programmers.

Behind the scenes, PHP compiles your script down to a series of instructions (called opcodes) whenever it is accessed. These instructions are then executed one by one until the script terminates. This is different from conventional compiled languages such as C++ where the code is compiled down to native executable code then that executable is run from then on. Instead, PHP re-compiles your script each time it is requested.

This constant recompilation may seem a waste of processor time, but it is actually not all that bad because you no longer need to worry about hand recompiling your scripts when you make any changes. On the flip side, many scripts take longer to compile than they do to execute!

Furthermore, it provides very quick feedback during development. If you have an error somewhere in your file, PHP will refuse to compile the page until you have fixed the problem, and you are able to step through execution of your code line by line until you find the problem.

The speed hit of regular compilation is nullified entirely by the use of PHP accelerators.

One major advantage to having interpreted code is that all memory used by the script is managed by PHP, and the language automatically cleans up after every script has finished. This means that you do not need to worry about closing database links, freeing memory assigned to images, and so on, because PHP will do it for you. That is not to say you should be lazy and make PHP do all the work - good programmers clean up themselves, and let PHP work as backup in case something is missed.

Perl

Perl is the most popular of the PHP alternatives out there, arguably because it is also the oldest. There is a large installed base of Perl out there; many open-source projects require Perl to be installed to work properly. It has the advantages of being very (very!) flexible, and also having a large collection of modules already written for it. However, it is let down by the fact that it is very easy to write obfuscated and confusing Perl without really realising you are doing so, and this has resulted in such marvels as the annual Obfuscated Perl Contest.

Well-written Perl scripts often look fairly like their PHP equivalent. The major cause for Perl's messy appearance is that many Perl programmers rely on "one-liners" - packing large amounts of functionality into just one line of code. Perl was once described very accurately by its creator, Larry Wall, when he argued that the front cover for his O'Reilly book on Perl should be a camel, saying that Perl was ugly but serviceable, and able to go long distances without much nourishment.

Perl is often a better choice when you want to take advantage of some of the pre-written libraries. CPAN, Perl's library repository, is very big, and there is a huge range of code for you to take, customise, and re-use. Perl also has a very active - and very cool - hacker community around it that's a whole lot of fun to be part of and is really a bedrock of support when you need it. Larry Wall and Damian Conway (both core Perl developers) are both rightfully revered as "alpha geeks" - people who really push the envelope of programming by doing cool new things. They are both very friendly, and and attend many conferences year round - go ahead and introduce yourself if you meet them, because they really are fascinating to talk to.

ASP

Active Server Pages (ASP) and ASP.NET is Microsoft's attempt to succeed in the web development market, and comes as standard with their web server, IIS. ASP has been mauled by the open source community ever since it came out, and they gave a variety of reasons: it is proprietary, single platform (Windows), and slow.

I would like to say, "Yes, yes, and yes", but I'm not going to try to pull the wool over your eyes. The reality is that ASP has been implemented on other platforms, and, when running on Windows and Microsoft Internet Information Services (IIS), is actually lightning-fast.

That coupled with the fact that you can write add-on modules for ASP using Visual Basic and COM would make the whole solution very attractive indeed if it were not for the fact that ASP only really works well on IIS. On other platforms there are many fewer features, and it generally runs a great deal slower. When running on Windows, the security issues and licensing costs tends to be the most important thing, particularly when an all-Microsoft solution stack is being used.
and
ASP/ASP.NET is generally favoured when an all-Microsoft stack is in place. When used on Windows, it is very easy to deploy .NET code to ASP.NET pages or even write your ASP pages using C#.

ColdFusion

ColdFusion used to be quite popular back in the hey-days of the dot.com boom because it is developed using a proprietary IDE designed for novice programmers who have no wish to see source code of any complexity.

For such a wizard-oriented system, ColdFusion performs fairly well. Performance is nothing to be desired, but development speed is good. Perhaps ColdFusion's biggest let-down is the price tag - you will certainly need to sit down before you see it. ColdFusion was bought out by Macromedia, and this has served to boost its corporate appeal in places where open-source is still frowned upon.

The main drawback to using ColdFusion is arguably its user-friendliness, which might sound odd at first, but let me clarify. With PHP and Perl, because the languages are so flexible, you have much more control over what happens and why. If something goes wrong in your code, it's normally very easy to track it down and solve the problem, or change your plans and implement a different solution to the same problem. Very often, stock ColdFusion has just one way to solve a problem, and this greatly reduces your control over the solution you make. However, at the very least, you can work using ColdFusion when you are in team with non-technical people.

The biggest advantage to ColdFusion is its IDE and the language it uses, "CFML" (ColdFusion Markup Language) - even junior programmers can learn the system and start making pages quickly. As a result, you will often find ColdFusion in use at very large companies where they use Visual Basic (another easy, but not very powerful or fast language) for offline work.

JSP

Java Servlet Pages has often been considered the "dark horse" in web scripting because at first many thought it would be overkill for the job and yet has managed to get quite a substantial community about it nonetheless. JSP has three key advantages over some of its competitors, which may be why it has done so well:
  1. It uses Java, a language that already has a large skill set of developers and a massive amount of functionality available. Java is also conducive to scalability as it distributes across multiple computers well.
  2. Sun, as well as other members of the community, has worked hard to promote the language and tools that support it, which means that JSP has a lot of backing inside larger enterprises.
  3. It strongly encourages templating of pages for maximum code re-use. Templates for PHP are widely available, but they are a great deal more popular in JSP.
It is a common argument that because JSP is based on Java it scales better than PHP. This is not correct per se in the same way that most other over-generalisations are not correct (yes, I realise that is an over-generalisation too, and hence you are free to enjoy the irony!) - PHP scales perfectly well as long as you write your PHP scripts usi andng the same design patterns you would have used writing your JSPs.

JSP is a popular choice when existing back-end business logic is written in Java also, as this keeps the development team language-homogenous.


From: http://www.hudzilla.org/phpbook/read.php/2_2_5

No comments: