An Overview of Web-Centric Languages
Audience and Intent
There are an enormous number of programming languages that are in wide use today. So many in fact that many people often wonder if we really need all of them. A language is analogous to any kind of tool that requires a skilled operator. If an individual with the know-how to make use of the language desires, he or she can use the tool to create something useful. Sticking with the tool analogy, the reason that we have so many languages is to allow developers to pick the right tool for the job they are trying to do. Different languages are useful for different kinds of things. Each has strengths and weaknesses.
In this article, I'm going to talk a little bit about four languages that are very widely used for web application development. They are, in no particular order, ASP, JSP, Cold Fusion, and PHP. I'm also going to talk a little bit about how web applications, which I may refer to interchangeably as "scripts" in this article, are actually executed.
I'm not going to go into a great deal of technical detail here, since this article is intended for a non-technical audience. My aim is to give that audience some knowledge of how these languages are used, what the pros and cons are for each of them, and how "application code" is injected into the design and layout of a web site.
Before I jump in, I should state for the record that I know and like PHP better than the other three languages I'm going to talk about. And I actively dislike ASP. I am going to be as objective as I can, but I cannot claim to be free of bias.
How Pages are Coded and Executed
Each of the four languages listed above live "on the web page" in a sense. In an HTML page, you have a bunch of tags that go around the content and tell the web browser what to do. I can make this word bold by putting <b> and </b> tags around the word "bold."
When a developer puts application code into a page, he escapes from the HTML by putting his code inside special tags. For example, in PHP, the most common way to do this is by putting your code inside of the tags <?php and ?>. So this might look like the following.
<?php ... php code goes here ... ?>
Different languages use different special tags to get out of HTML, but you get the idea.
Now, if you do a "view source" of such a page, you won't see any of the programming languages code or the special tags. Here's how the page actually gets executed. A page with a .html extension will get sent from the web server directly to your browser. However, if the page has a different and appropriate extension, such as .cfm in the case of Cold Fusion, the page does NOT go right out when it's called. Instead, the language engine that you are using reads through the code. When it finds the special tags it evaluates all the code that it finds in them, and inserts the output from that piece of code where the code used to be. Then it gets sent to the browser as normal HTML data.
The code in the tags could do any number of things. It could get data from a database, print out the current date, or pull and then print out information from some other network resource. But this is basically the life cycle of a dynamic web page.
(I should note that the above execution model is not technically correct in the case of JSP. But unless you're really concerned about things like the Java Virtual Machine and how the web server works it's effectively true, and you can think about it this way without getting into trouble. I should also point out that the bit about the file extensions is true for default configurations. In real life you can configure your web server to do lots of different things. But I digress...)
ASP
This stands for Active Server Pages. It is a technology developed by Microsoft for use in their IIS web server product. It works as explained above, by putting your ASP code onto a web page within special tags that tell IIS where the programming code is.
A point of some interest is that the ASP model is not technically tied to a specific programming language. It is possible to program ASP pages using things like JScript (Microsoft's version of Javascript) or Perl. However, practically speaking, everybody who is really doing ASP development using a language called VBScript. This is syntactically the same (meaning that it's the same style of coding) as Microsoft Visual Basic, which is Microsoft's version of the BASIC language. You can think of it as BASIC on major, major steroids.
Many people like programming using Visual Basic and VBScript because they feel the language is fairly easy to learn and use. Personally, I can't stand it, but there are many smart people who disagree with me. ASP pages programmed in VBScript integrate very easily with other applications and programs from Microsoft, such as COM objects (pre-built bundles of available functionality) and Microsoft databases. On the downside, using ASP basically ties you to Microsoft servers, operating systems, and other products. There are ways to run ASP pages on other platforms, but it's basically an emulation trick. If you want access to the real power that's available, you should stick with Microsoft all the way.
Pros
- Integrates very will with other Microsoft products.
- Produces efficient code that runs quickly.
- You have access to a lot of functionality made available by Microsoft platforms.
- Plenty of ISPs support it. Plenty of developers know it.
- It's free, in that it doesn't cost anything.
Cons
- You are tied to Microsoft Operating systems and web servers.
- You'll be coding in VBScript (did I mention I hate it?)
- Notorious for security holes.
Overall, my feeling about ASP is that it's a good choice if for some reason you know you will be using a Microsoft operating system and web server. Many times, this reason is because the client has a database in something like Microsoft Access that they want to use. In this case, ASP is a good choice for a development language.
JSP
In a manner analogous to the above ASP, JSP stands for Java Server Pages. As I'm sure you've surmised, these are written using the Java programming language that was developed by Sun Microsystems. This language, ulinke some other examples here such as Cold Fusion, can be used to write much more than web applications. Java is used to write programs on everything from desktop applications to cell phones.
However, we're interested in the web side of things in this article. As with ASP, the Java code that you put on your pages goes inside special tags. When the page is requested, there is a program that I'll call the "Servlet Engine" that interprets the Java code, puts the resulting output into the HTML on the page, and then sends the page on to your browser. Again, I should note that this is something of a simplification, but it's probably safe for you to think about things this way.
There are a lot of nice features that you get when developing in JSP. To begin with, you have access to all of the functionality provided by the Java language, and that is really a lot of functionality. Also, Java runs on many different platforms, so you are not tied to a particular operating system or web server. JSP pages are very efficient if coded correctly, and these applications tend to be good at scaling to very large systems.
There is, however, a fairly important downside. As noted, with JSP you are coding in Java. Out of the languages listed here, Java is BY FAR the most complicated one to write code in. This means that application development is typically considerably slower than with something like PHP. If you are new to application development, it will take MUCH longer to learn how to write good JSP than good Cold Fusion, PHP, or ASP.
One last important note concerns the web server. With JSP pages, as I said above, you have something external to the web server called a "Servlet Engine" that actually does the work of interpreting the Java code. There are many that are available for use. Some of them are free, while some cost a great deal of money. In either case, setting these up properly can be a complicated process that adds even further to the hurdles you may face when using JSP.
Pros
- Runs on many different platforms.
- Gives you access to a great deal of functionality through Java.
- Very efficient.
- Scales well to large applications.
- Integrates very well with high-end databases such as Oracle.
- Can be free, in that it may not cost anything.
Cons
- Java code is harder to write than other languages listed here.
- Development time is usually longer.
- Can cost a lot of money depending on your choice of server.
- A comparatively small number of ISPs support it.
My general feeling about JSP is that it's best when you are writing large, possibly distributed, high-end applications.
Cold Fusion
Jumping to the other end of the complexity spectrum, we have Cold Fusion. This technology is characteristically different than the other three in that the Cold Fusion "language" is all tag based markup, whereas the other three are actually proper languages. I'll translate that into non-geek.
A standard programming language needs to meet a qualification called being "Turing complete" but I'm not going to even start in on what that actually means. In a concrete sense, each language has its own syntax that it uses for code. Here's a little tiny bit of PHP to look at.
<?php // assign my name to the variable $name $name = "Chris Lea"; // print it out print "Hi, my name is $name"; ?>
This looks pretty sensible. Obviously, it would just print my name out to the page. But the thing to note is that there's a programatic syntax for things like assigning variables or calling the print() function. I'm harping on this because Cold Fusion takes an entirely different approach. The language is TAG BASED. So programming in it basically means that you have to learn a bunch of new tags that will seem pretty familiar if you've ever done any HTML coding. For example, the above example might look like this.
<cfset name="Chris Lea"> <cfoutput> Hi, my name is #name# </cfoutput>
The purpose of this is to make the Cold Fusion learning curve as shallow as possible. The idea behind it is that there are tons of different tags that do many different things, but you'll be comfortable using them because you're already used to markup (tag based) languages. And, in practice, this works rather well. Cold Fusion is designed to make certain things that you're likely to do a lot as a developer very easy. These include creating forms that validate their results with javascript, connecting to databases, performing SQL queries, looping through result sets, and doing site wide content searches.
And when I say easy, I really mean it. The downside happens when you want to do something that they don't have built in to the available tag libraries. In this case, it can be harder to create the desired functionality because you can't approach problems in a normal programmer fashion. For example, in JSP if you need a function that's not in the language, you just write a new function. In Cold Fusion, you have to create your own tag to handle your problem. This is certainly not impossible, but it can be a pain at times. Having said that, I wasn't joking when I said they have a ton of tags. It's not too often that I've found myself having to write something complicated outside of what they've provided.
Pros
- Easy to learn.
- Runs efficiently on many platforms.
- Makes some common tasks very easy to accomplish.
Cons
- Server software is somewhat expensive.
- Tag based scripting can make custom development annoying.
My overall feeling about Cold Fusion is that if it has the functionality to do what you're trying to do, it's a great way to go. You can get apps up and running very quickly and they will work well. However, if you need a lot of highly customized functionality then you should use a more traditional language.
PHP
Finally, my favorite of the group, PHP. In standard UNIX naming fashion, this stands for the recursive acronym PHP: Hypertext Preprocessor. It executes in a similar fashion to JSP or ASP, and has a syntax borrowed from other popular languages such as Perl and C. In fact, if you are familiar with Perl, then learning PHP will be almost trivial for you.
One advantage it does have over ASP or JSP (which use VBScript and Java as languages, respectively) is that it was designed from day one for use in web development. This means that the API (which is geek talk for "the available functions") is particularly easy to deal with if you are writing a web based application. Also, the language doesn't have a lot of functionality in it that's not directed towards web-based use. A final point of interest is that it's the only language listed here that is open source software, meaning that the source code for the language itself is freely available. It's developed by a team of people around the world, and all with the appropriate know-how are encouraged to participate.
The functionality available in the language has been growing rapidly over the last few years and probably will continue to do so. There are functions to handle databases, arrays, XML, dynamic image generation, and too many other things to list here. The language itself also supports fairly simple object oriented programming as well as procedural techniques. It probably runs on the widest array of different platforms of any language listed here since it will work on just about any flavor of UNIX as well as Windows and Mac OSX.
Probably the most critical flaw is that it is hard to make PHP applications scale up to very large sizes. Doing so often requires the abilities of very talented system administrators who can juggle database servers, application servers, and web servers well. It is slightly more difficult to learn than Cold Fusion, but definitely easier than learning the Java needed for good JSP coding.
Pros
- Free as in no cost and available source code.
- Very web-centric language shortens development time.
- Functionality for a large number of things provided by API.
- Available at tons of ISPs on many, many different platforms.
Cons
- Hard to scale to very large applications.
- Harder to learn than Cold Fusion.
My general feeling about PHP is that for small to medium sized applications it really can't be beat. The only time that I don't use PHP given the choice is if the project is VERY large, in which case I'm usually only working on a tiny part of it. For your typical ISP situation it works great.
Conclusion
I hope this has provided some insight about the languages in use for web based application development at the current time. The links at the top of the article will take you to the respective homepages for the different languages. Good luck with your apps.