Stefan Rusek | Ready to Quit ASP.NET

Ready to Quit ASP.NET

Wednesday, February 11, 2009

About four years ago, I wrote a little CMS with support for plugins and a number of other neat features. I continued to work on it off and on until I went to work for Fog Creek. Since then, it has languished in a Subversion repository on my hard disk. I don't have any desire to resurrect it, so the repository will probably get converted to Mercurial and then languish for another four years.

At the time, I spent a lot of time figuring out how APS.NET ticks. It is really a remarkable system. Originally, it was designed to allow Visual Basic programmers to transition to writing web apps without having to learn much about web programming. Yet for all its power and cleverness, is just plain fails. It failed in 2001 and fails even harder now.

The idea that you can shield web developers from having to get into the nitty-gritty and learn HTML is just cuckoo. HTML is the minimum any web developer should know, and in today's web, they should also know JS and how to use jQuery or a similar JavaScript framework. While ASP.NET tries to save you from doing that, its abstractions leak so badly that all the boys in Holland couldn't plug all the holes. Even if it did, despite its powerful control library, ASP.NET does not make it easy to do something it was not specifically designed for--and it was designed pretty narrowly.

Let's look at what happens when you, a neophyte web developer, first encounter ASP.NET. If you only use the controls provided in System.Web.dll, and write all of your own controls using the UserControl abstraction and learn HTML, you can create a half-decent web app using little more than your existing VB knowledge. That is, until you create a page that has a lot of cool stuff on it, at which point your 20K page turns out to weigh in at well over 500K. After a little research, you will find the culprit turns out to be ASP.NET ViewState. So you turn it off and your page is tiny again, but now none of you controls remember their values when buttons are clicked. You do some more research and learn that each control stores is value in ViewState to pass data across page loads, so you go through and determine whether you should enable or disable ViewState for each control. When you're done, even if you have something that mostly works, you have a big page instead of a huge page--and the abstractions designed to save you from learning about the web have merely forced you to learn the arcana of how ASP.NET tries and fails to hide the web, instead of writing a well-written web application from the beginning.

The remaining source of hugeness turns out to be a list control that you databound to a giant list of things from the database. The database can give you paged data, but the list control doesn't really like to be given anything but the full list--even if the control only shows a subset. At this point, you can either dig into the inner workings of the list control and try to trick it into doing what you want, or you can write your own list control. Either way you have a ton of work ahead of you.

The basic problem is that ASP.NET is not built on top of a windowing framework, but it tries its hardest to act like Windows Forms. So the abstraction breaks down whenever you run across the two big differences between web development and windows development: state management and how to display your controls--or in other words, basically the whole thing.

In an AJAX world, ASP.NET is even worse, because the idea of rendering only part of the page just does not map well into ASP.NET. Microsoft has an AJAX library that is built around the concept of an update panel control, which allows you to specify a chunk of the page that can be replaced via AJAX. This works for small things, but before too long, you put almost all of your page inside update panels. The end result is that each time you need do an AJAX request, almost the entire page is sent to the client and replaced via JavaScript, so even if only one control needs to be rerendered and replaced, all of them are.

ASP.NET MVC which throws away most of the ASP.NET infrastructure and builds up an MVC framework on top of the IHttpHandler interface (the lowest level part of ASP.NET). The MVC design pattern as applied to web design is inherently stateless, so even though the programmer is forced to actually think about state management, he writes cleaner, shorter code. The other thing it does right is to provide a set of extension methods that encourage the programmer to generate a bunch of html strings instead of an tree of controls.

In my experience, a good VB developer should have no problem learning to write good web apps, even ones that do neat AJAX tricks. Unfortunately, ASP.NET tends to prevent those programmers from being successful rather than help them.


Helmut Irle said...

I've had similar experiences with ASP.NET. After being involved in a larger social networking site written in ASP.NET 2.0, I am now starting to learn Python and Django. I just got sick of the way ASP.NET works. Maybe I should have given ASP.NET MVC a chance to change my mind, but I'm quite keen on moving away from Microsoft technologies for a while. I still code in C# otherwise, just not ASP.NET. But my use of .NET will probably slowly decrease, until I make Python my main programming language at some point, hopefully.

on Friday, February 13, 2009
Steve Sheldon said...

So what is your opinion of ASP.NET MVC? Are you recommending using it over WebForms or what?

I agree that I am so done with WebForms. I was looking at some code the other day at a client, the guy had written a Server Control to handle a tab menu. Ok, but this was around 300 lines of code and configuration just to display a ul/li list. Horribly complex, and server controls have long been poorly documented compared to HTML.

on Friday, February 13, 2009
Stefan Rusek said...

I heartily recommend using ASP.NET MVC. This site uses it and it is so much more pleasant to work with!

on Friday, February 13, 2009
Paul Mendoza said...

I've been using ASP.NET for the last few years and I'm always pretty concerned about page sizes. But I find that it's not too big of an issue for me as I can generally control it fairly well. For UpdatePanels you can set them to be conditional which a lot of people dont do. If it's conditional it will only update if it's told to update so you can make your AJAX requests very small.

The biggest problem I see people have with doing development is session variables and creating tons of them. It can get very sloppy across pages and controls.

on Friday, February 13, 2009
Stefan Rusek said...

@Paul You are totally right that a careful programmer can create high quality web apps using ASP.NET as is. The problem (as I see it) is that too many of the things that must be done are not intuitive to the programmer new to ASP.NET, which greatly increases the amount of time before a developer can create a proper web app.

on Saturday, February 14, 2009
Please log in or register to comment.