Debate – .NET V. PHP: Top 6 Reasons to Use .NET Article

Tweet

Welcome to another SitePoint Debate. Today, daggers are drawn over that long-running battle of the technological titans — Open Source and Microsoft.

Specifically, we ask “Does .NET mean the end for PHP?” Judge for yourself…

First of all, I’d like to clarify that I’m a PHP guy. I’ve coded in PHP for the last 2 years, and all my current sites are built in PHP and MySQL. I’ve never liked ASP during my time as a Web developer, and still dislike it. However, ASP.NET is an entirely different matter, which I’m learning now, with great enthusiasm. This article is targeted at PHP developers, designed to show some of the cool stuff ASP.NET has to offer. And after all, there’s no reason you can’t know both ASP.NET and PHP.

What is the .NET Framework?

The .NET Framework consists of two main parts:

  1. the CLR (the thing that runs code), and
  2. a hierarchical set of class libraries (Think PHP functions + the PEAR libraries, extend them a little, and have them organized in a very nice hierarchical structure). Included in those class libraries are ASP.NET, ADO.NET (a data access system) and Windows Forms (classes for building windows apps).

The CLR can run code written in any language that’s adapted to .NET, and can run it on any operating system that has a version of the CLR. In other words, kind of like Java that doesn’t have to be written in Java.

An Example: The Web Forms Framework

ASP.NET has a kind of templating system on steroids called Web Forms. I mention this first because it’s this system that got me interested in ASP.NET in the first place, and is, in my opinion, the best feature of ASP.NET. There’s nothing like it in PHP yet, to my knowledge. It goes something like this:

<select id="ColorSelect" runat="server">
<option>SkyBlue</option>
<option>LightGreen</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
</select>
<span id="Span1" runat="server">Some text.</span>

Notice that the above is just ordinary HTML, with the addition of the runat=”server” attribute in the <span> and <select> tags. Now, to add an option to this selectbox, you would include the following in your ASP.NET code (which, by the way, can be separated completely from the HTML):

ColorSelect.Items.Add('AzureBlue');

And to manipulate the <span> tag, you would do this:

Span1.Style["background-color"] = "red";
Span1.InnerHTML = "Changed text!";

…and the system outputs 100% valid XHTML to the browser:

<select id="ColorSelect">
<option>SkyBlue</option>
<option>LightGreen</option>
<option>Gainsboro</option>
<option>LemonChiffon</option>
<option>AzureBlue</option>
</select>
<span style="background-color: red;">Changed text!</span>

Besides the fact that this is very cool, it also makes collaboration with the clueless HTML/Designer guys much easier. This is only a very simple example of what the Web forms framework is capable of, and if you’re interested, you can check out more examples in the ASP.NET Quickstart tutorials over at GotDotNet.

6 Great Reasons to Use .NET

1. Speed

Just like all .NET applications, ASP.NET applications are compiled. This makes them much faster than PHP, whose applications are interpreted. To achieve the same effect with PHP, Zend and PHP accelerator must be installed on the server, and this is rarely the case at most Web hosting companies. Also, OO is much faster in ASP.NET than it is in PHP.

2. More Language Support

ASP.NET is written using “real” OO (Object Oriented) programming languages of your choice. PHP is just a simple scripting language in comparison to .NET languages like C++, VB.NET or C# — languages that give you more control, and more reusability. That said, these languages are also harder to learn and master, and might be intimidating if you haven’t been programming for very long. ASP.NET, for example, can’t be picked up as easily as PHP, though C# is not very hard to learn if you already know PHP.

Another good thing about .NET is that it has multi-language support. You can currently write (or will be able to in the very near future) ASP.NET applications in C++, C#, Visual Basic.NET, Jscript.NET, Python, Perl, Java (J#), COBOL, Eiffel and Delphi. You may even find yourself writing your ASP.NET applications in PHP in the future — it’s not impossible!

What’s nice about this is that you can mix the code. can instantiate an object in C# from a class written in C++ or VB.NET. This increases the programmer hiring pool for companies, and improves your chances of finding a suitable pre-written class for your project on the Web.

3. Your Choice of Development Environments

This is an area where ASP.NET shines!

Microsoft has released a free development environment for ASP.NET called Web Matrix, which blows all other free development environments for PHP out of the water. It has a built-in Web server, database administration interface FTP integration, and more. Not only that, Microsoft has also released MSDE — a free development edition of MS SQL server. It has precisely all the features of the full MS SQL server 2000, and any application you write for MSDE will run fine on MS SQL Server.

If you can afford Visual Studio .NET, it, too, offers some amazing qualities. It allows you to:

  • automatically create reports and diagrams from your databases,
  • debug the code line by line, while at the same time seeing what happens in the application,
  • assign a temporary value to a variable in the middle of execution, in order to test out different scenario,
  • hover the cursor over variables in your code while debugging, to see what value they have “right now”,

…and much more.

4. It’s Part of .NET

ASP.NET is a part of .NET, and that benefit is too large to simply ignore. If you know how to write ASP.NET applications, you know how to write ordinary applications too. Even windows apps, if you read up a little on the Windows Forms classes (as opposed to the Web Forms). PHP has PHP-GTK, but it’s currently very immature compared to .NET.

5. It’s Cheaper to Develop for

Didn’t expect that one, did ya? It even surprised me! Due to the fact that ASP.NET is such a powerful application, and it’s offered for free (including the code editor, Web server, and FTP client), I actually ended up paying less ($0) than I did for my PHP Development Environment composed of UltraEdit ($35), Bullet Proof FTP ($30) and mySQLfront ($0). With that said, hosting ASP.NET is still more expensive than PHP.

6. It’s Cross-Platform

.NET is currently pretty much tied to the Windows platform. This is a bad thing, but I’m quite confident that .NET will become very cross-platform in a few years. Why? A while back, Microsoft released Rotor, a Shared Source implementation of the CLR (CLR = The thing that runs code) and most of the non-windows specific class libraries for Windows and BSD Unix, with source code for both. When I first heard this, I didn’t believe it — that REALLY didn’t sound like something Microsoft would do. And when I realized that it was in fact true, I expected Rotor to be the smallest and most feeble implementation Microsoft could possibly get away with.

I couldn’t have been more wrong. Rotor hasn’t been built on the cheap — it’s practically identical to its commercial counterpart in most important respects. .NET also has a very powerful Platform Abstraction Layer, making ports to other operating systems pretty easy to achieve. Not only that, but the CLI and C# are now standardized by ECMA. And the Mono project, with Ximian behind it, is working on an Open Source implementation of the .NET framework right now. All these factors lead me to believe that the chances for .NET to become cross-platform are very high.

Try it!

But don’t take my (or Harry’s) word as gospel! Try ASP.NET out for yourself. First, download the .NET framework (21MB), then download MSDE (MS SQL 2000-light I talked about earlier — 33MB) and finally, ASP.NET Web Matrix (1.2MB).

Once you have these installed, you’re ready to develop ASP.NET applications — go check out the official ASP.NET Quickstart Tutorials, or even better, Kevin Yank’s excellent article series on beginning ASP.NET. Enjoy!

Hear both side ot the argument! Find out why the opposition thinks PHP is superior, and make up your own mind!

Free book: Jump Start HTML5 Basics

Grab a free copy of one our latest ebooks! Packed with hints and tips on HTML5's most powerful new features.

No Reader comments