Thursday, May 21, 2009

Debate(part I) - .NET V. PHP: Top 6 Reasons to Use .NET

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.



Continued in next article....

No comments:

Post a Comment

About Me

Hyderabad, Andhra Pradesh, India
I'm a MCA graduate working as a Web Developer.