Friday, June 19, 2009

ASP.NET traps for young players

No other area of programming seems to have as many inexperienced, beginner 'programmers' taking on contract tasks that they have no idea how to perform, than ASP.NET. I guess everyone wants a cheap website. There's a few ways that the framework does not help.

When you create a default page, it will have a page load event in it. As a result, a lot of people write all their code in the page load event, and never add a page prerender event. Because of the order of the page lifecycle ( that is, page load, then events fire, then page prerender ), the prerender is often the only event you really need to handle, and it's the one that any data bound page should handle. This leads to several issues.

First is the "I push a button and it doesn't work, I push it again and it does" scenario. This means they bound to a data source, then the event changed the data source, so, on refresh, the changed source is loaded and bound to, but the first time, the data was loaded before it was changed. Then there's the 'my control loses it's selected value' problem ( which should ideally be fixed with a !IsPostback block, but would also be fixed in terms of reading the value in code behind by reading the value first, then data binding ).

The next thing I don't understand is, if I write a site in VS, and use the built in web server, it will allow me to write code behind like this:

if (!someTest())
{
MessageBox.Show("The test failed, please open a file");
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
}

This apparently WORKS in Visual Studio. So, every day, when people in a certain continent clock in for work, programming forums worldwide get the 'This works on my local machine, but when I deploy it, it gives me this error on the server, what does it mean ?' question. Now, it's true that this is a problem with the so-called programmer, and it's true that the error message explains the issue in plain English, but, as far as I can see, the MVP program exists to give people incentive to provide Microsoft tech support by answering these sort of questions, so I assume that having these people write code is part of Microsoft's business model. I am guessing they skim the cream of the programmers in these low wage countries for their own benefit, I don't know. Either way, why would you create an IDE that allows you to write code that is plainly not going to run on deployment, under any circumstances ?

And don't get me started on how AJAX fits into this mix. Most people using the ASP.NET AJAX library, both think it IS AJAX, and think that Microsoft invented AJAX. They certainly have no idea what AJAX is, or what it means, I see questions every day that say 'I want to use AJAX to do xxx', where xxx has nothing to do with AJAX, although it may involve javascript. It's become the new XML, if you write a website, you need to use AJAX, where-ever you can. As the AJAX library does include some controls that don't really need AJAX to exist, the line is blurred even further. The ASP.NET AJAX library is also horribly inefficient, when I worked on a website in ASP.NET that used AJAX, I rolled my own code, because our site had far too much traffic to pay the price of the library. I am glad, because it means I was able to learn how to hand code AJAX, and I believe anyone who uses a library, should have some idea of what it does, so they know what performance cost is associated with their actions.

Of course, in .NET, it's not deemed important to even make the decision between a vector or a list, so I guess performance doesn't matter nowadays.....

1 comment:

  1. its true ....
    ASP.NET makes website development much easier ...
    so beginners are inclined towards it ....

    ReplyDelete