Competing Languages

Much to the chagrin of a large group of developers, PHP is not the only option available to web developers, and, although I really am leaving myself open to flame-mail here, PHP is not always the best option, either.

In order to make sure your PHP education is rounded, I want to introduce you briefly to the other web development languages on offer, how they compare to PHP, and, where appropriate, when a language is a better choice than PHP for a certain task.

2.2.5.1 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 attend many conferences year round - go ahead and introduce yourself if you meet them, because they really are fascinating to talk to.

2.2.5.2 ASP.NET

ASP.NET is Microsoft's attempt to succeed in the web development market, and comes as standard with their web server, IIS. ASP.NET 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.NET has been implemented on other platforms, and, when running on Windows and Microsoft Internet Information Services (IIS), is actually lightning-fast thanks to its .NET back-end.

That coupled with the fact that you can write back-end code for ASP.NET using C#, VB.NET or any other .NET language 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 licensing cost tends to be the most important thing, particularly when an all-Microsoft solution stack is being used.

ASP.NET is generally favoured when an all-Microsoft stack is in place.

Author's Note: If you're migrating from ASP to PHP, you might consider using ASP2PHP, a freeware converter between the languages. Although it isn't perfect, it can give you a big head start if you are trying to migrate a large project. Your best option is to use the tool, then go over the generated scripts by hand to make sure there are no bugs or performance issues. You can download ASP2PHP from http://asp2php.naken.cc .

2.2.5.4 Ruby on Rails

I'm not going to pretend that Ruby's syntax is nice, because it's not. But Rails manages to make it cool by doing a huge amount of the hard work for you - it leaves PHP in the dust in terms of usability. Rails development is quite closely associated with Apple, and the two share one big thing in common: once you switch to them, you rarely switch away.

In the case of Rails, it's sadly not because of its awesome performance - Rails is dog slow compared to PHP, which is why you rarely see it used on large websites. However, a common programming adage is "computer time is cheap; programmer time isn't" so if you have huge system resources at your disposal and don't mind using up a few thousand extra CPU cycles in exchange for faster development, Rails might be for you.

2.2.5.4 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 using 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.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: When to use PHP >>

Previous chapter: Performance

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.