29 Dec
2008

What Would You Choose For New .NET Web Development?

Category:General PostTag: :

Web development in the .NET world has gotten a lot more interesting in the last couple of years. A few years ago, the only choice we had for a web front-end was ASP.NET WebForms. Nowadays you can add ASP.NET MVC and Silverlight to the mix. Obviously each option has its pro’s and con’s, so it’s not always clear which option should be used when you’re starting to build a new Web application.

Let’s start with ASP.NET WebForms. This is the option that has been available since the .NET platform was introduced, so there are already a lot of people experienced with it. There is also a ton of information available about the ins and outs of WebForms. And when it comes to commercial tool vendor support, it’s clearly miles ahead of the other options since there are lots of commercially supported controls available for it. Unfortunately, WebForms was originally created to offer a similar development model to WinForms developers. The code-behind files and the event-driven way of working is very similar to how you would write code in WinForms applications. Obviously, web applications and windows applications are completely different things, so you can’t reasonably expect the same way of working to be suitable for both.

Particularly, the Page and Control lifecycles are rather complex (at least much more complex than i would think they’d need to be) and often cause weird issues on complex pages. The event-driven model of both the Page class and the Control class (and its derivatives) seem to be the major cause of this. I think most WebForms developers have on more than one occasion spent long times debugging weird situations which were ultimately related to certain events triggering unexpected behavior in other controls on the same page. Granted, people with an in-depth knowledge of how these lifecycles really work don’t run into this as much, or are capable of avoiding these problems altogether.

You could indeed make the argument that most of the problems that people are experiencing with WebForms are caused by those people’s lack of understanding how it really works and how it really should be done. On the other hand, that is a pretty good sign that WebForms development isn’t intuitive or clear enough, and that while Microsoft has tried hard to make it easy to use, most people seem to solve their WebForms problems by hacking around their problems, or playing around with settings until it seems to work.

Another major problem with WebForms is that it doesn’t easily enable Test Driven Development. True, there are various patterns you can use to make sure you can write testable UI logic (up to a certain point anyway) but all in all, these approaches require more effort than should be necessary and you often end up wrapping a lot of stuff just to be able to test it. WebForms in general was never designed with testability in mind, and you will most definitely be confronted with that if you try to write testable UI code with WebForms.

As you can probably tell, i’m not a huge fan of WebForms. I think it’s fine for simple applications, but for anything beyond that i’d like to avoid it as much as possible.

Microsoft’s upcoming ASP.NET MVC framework aims to fix much of the issues i’ve mentioned above. It was designed with testability in mind, and although it’s not perfect either (depending on who you ask), it is certainly a huge improvement over WebForms when it comes to writing testable UI code. You also have a lot more options when it comes to having the framework behave the way you’d like it to. Another important benefit is the fact that ASP.NET MVC kinda forces you to structure your code in a much more sane manner. You put as little logic as possible in the views, and you put most of it in the Controllers where it belongs. Obviously, that doesn’t mean you should put business logic in the Controllers!

One of the downsides of ASP.NET MVC is that, due to its completely different way of working compared to WebForms, it comes with a much higher learning curve. Experienced WebForms developers might struggle with it at first, and might even be frustrated because most of their hard-earned WebForms experience no longer gives them a benefit. Some will probably enjoy it much more than WebForms, and some will probably dislike it strongly because it’s so different. Another downside is that there are far less commercial tool vendors that are offering ASP.NET MVC controls, at least compared to WebForms. Although that might not be that big of an issue, since i suspect that it’s easier to develop nice looking and reusable controls yourself when using ASP.NET MVC than it is to do so when using WebForms.

If you’re starting out with ASP.NET MVC, i think it’s safe to assume that you won’t proceed as quickly as you’re used to at first. But once you’re used to the new way of working, i’m pretty sure that it enables you to rapidly implement new pages and new functionality in a very clean way. For true web applications, i would probably pick ASP.NET MVC everytime, unless you don’t have the room to get over the learning curve. Also, when combined with a client-side javascript library like JQuery, this approach seems very compelling. Yes, i know you can use JQuery with WebForms as well, but it just seems to lend itself better to the MVC approach.

And then there’s Silverlight. There are already a couple of reasons why people would not want to use Silverlight for web applications. For starters, even though the application is running in a browser, it’s not really a true web application is it? Your users can’t bookmark pages, using the back button leads to unexpected behavior, there aren’t that many options for Search Engine Optimization, etc… However, if your only web-related requirement is that your application needs to run in a browser, without having to worry about any of the typical expected requirements for web applications, then Silverlight is a pretty interesting choice as well. You can very easily create very rich applications, with possibilities that are either impossible, or extremely difficult to do with typical web development platforms.

Our Genesis web front-end is developed in Silverlight. The UI not only looks great, but you can navigate between all of the available data in a manner that is simply much easier to develop than it would be for typical web apps. It’s very easy to create that ‘wow’-effect with your users in Silverlight. Obviously, that ‘wow’-effect isn’t the most important part of your application, but it does count for something.

Another interesting aspect of Silverlight development is that you can go back to a more statefull development model compared to the typically stateless nature of web aplications. After all, the cost of that state is no longer something your web server has to bear. It’s now the client who has to keep that state around, so you can avoid a few extra roundtrips here and there as well. Then again, you really don’t want your Silverlight application using huge amounts of RAM in your user’s browser either so you do need to take care not to go overboard with it. The development model is completely different than both WebForms and ASP.NET MVC, but if you already have people with WPF experience the learning curve is probably not that high.

However, testability isn’t great (yet) when it comes to Silverlight. It’s possible to write testable code, and you can execute tests in the Silverlight runtime, but it doesn’t really lend itself to a true TDD approach yet although i hope that will improve in the future.

So there you have it… the three options for .NET web development. I’d stay away from WebForms altogether from now on, and i’d decide between ASP.NET MVC and Silverlight on a case by case basis. What, you weren’t hoping for a definitive answer were you? 🙂

I would be interested in hearing your thoughts about pro’s and con’s of any of the options… particularly things that i haven’t mentioned, or if you just plain disagree with my statements. Which option would you prefer to use, or not to use?

20 thoughts on “What Would You Choose For New .NET Web Development?

  1. Poor Dynamic Data, doesn’t deserve even a mention? 🙂

    Yesterday I was talking to a colleague how the DD guys might be a bit envious of all the attention that ASP.NET MVC is getting..

    On another note, Roy Osherove has been twittering some Silverlight testing he is doing, so he might show up with some cool news soon…

  2. You forgot asp.net Ajax, this is currently the best of the three because
    1) MVC isn’t released yet
    2) Silverlight has three big issues first is security and web service calls (must use SSL minimum but no advanced security features) and second is that your essentially giving your code away, so if you have app with several big parts which shouldn’t be shared you need a way to build composite app with silverlight, very complex, and three there is no mobile for SL.
    3) Ajax with JSON web services is best of all worlds if you add on some javascript framework it is even better experience.

    I do think MVC will be the way to go in the future, but it has to be released before it is a real option.

  3. Lucas: One has to use ASP.NET Ajax with Web Forms or MVC, so it is not a mutually exclusive thing. Regarding MVC, it is on Beta “Go Live” and the API is stable, so I am not sure what difference its release will make really (except books being finally released), people is using it for production stuff already.

    When it comes to Silverlight, I think the rise of such powerful javascript libraries like jQuery and YUI is making it less attractive. It will still be used a lot for desktop-like experiences, but for rich and snappy UI only it might be redundant. Not to mention that WPF is scary and Microsoft doesn’t seem to be pushing it to every web developer.

  4. the ASP.NET MVC RC is very close to being released, so i guess it’s a pretty viable option already

    and yes, Silverlight probably doesn’t really have a big advantage over MVC when it comes to typical business applications. But i can definitely see it being extremely interesting when you need more than just your typical business UI.

  5. Why not Castle MonoRail?

    It’s probably the most battle-tested (both in unit test coverage and in production implementation) MVC platform currently available for ASP.Net. Sure, ASP.Net MVC will eventually catch up, but until that happens, MonoRail certainly deserves a look.

  6. I really enjoy ASP.NET MVC. I actually find the learning curve is not as steep as with Web Forms, because MVC works the way the web works. As such, things just flow. Whereas with Web Forms you’re constantly struggling to figure out ways to work around web forms to do what you want/need. That’s the hard-earned webforms experience you speak of.

    I’ve also started working with jquery more, and amazed I’d not done this before. Combined with MVC, it’s super cool.

  7. Davy,

    If you’re concerned about Castle MonoRail’s future, look at NUnit. Microsoft came out mstest, NUnit(and MBUnit and all of the others) are doing fine. It’s competition.

    The worst thing that can happen to ASP.NET MVC(which i use) is for MonoRail(which i also use) to go away, lack of competition(which leads to innovation) will shoot the ASP.NET MVC framework in the foot.

    -c

  8. I’m biased, but I think our framework, Gaia Ajax is worth to mention in regards to a fresh start on ASP.NET.
    Make faster web apps, with less code and no JavaScript at all.
    Still have full control. 🙂
    Check our samples for upcoming release: http://sandbox.gaiaware.net/themis-beta2/

    And we’re Open Source, if you are building open source, we are free as well.

  9. well yeah, NUnit (and the others) are doing fine…. but MSTest is still a piece of shit though (IMO)

    ASP.NET MVC is a lot better in what it tries to accomplish than MSTest is, so the comparison doesn’t really hold up

    i agree that competition is great and necessary, and i really hope that MonoRail remains under active development. Ken Egozi (the MonoRail maintainer) has already assured me that that is his goal as well.

    If that is indeed the case, then MonoRail is an excellent option as well.

  10. lol..i had actually typed something to the effect of MSTest is a piece of shit but then deleted it figuring i’d try to be a little kinder…

    that said, i’d pick anything other than webforms. ASP.NET Ajax(think MSTest) is tacked ontop of asp.net webforms, so is gaiaware. jQuery and Prototype/Scriptaculous solutions do everything better than ASP.NET Ajax, gaiware does the same thing as ASP.NET Ajax, except it’s called gaiaware, both of them have to have something on the backend to answer all of those ajax requests, which judging from the runat=server attributes, is asp.net webforms.

    however, all of this depends on the app you’re building. Just a quick little demo for a customer? I’ll whip up some screens using webforms and mostly straight up html(ie no server controls). small little app that doesn’t plan on growing and has little use? prolly webforms html again. An app with any complexity and needs the ability to grow in size and complexity? MVC(any flavor) fo sho.

    -c

  11. Any person who has a business mindset will not use asp.net mvc before it has cycled through sp1. You put your business in jeopardy. MVC is not new, but Microsoft has to come up with better development support before it can sell this technology. It has to be something you configure and drag-and-drop and those tedious, repetitive code should be generated for you. Anyone just enjoy typing code, not the result should not be assigned any important role in IT related software development. Reserve the fast code typist for low level, C/C type of project, not the IT related projects.

  12. Looks like those who don’t like webforms really didn’t go beyond little drag-and-drop demos. People who have gone all the way through webform will laugh their heads off about you MVC guys grunt against Web Forms. If you look at the ASP.NET MVC code, it reminds you of asp and spaghetti code.

    Microsoft has touted asp.net webform as MVC before in their pattern practice group. In my view, it’s a much better abstraction. All you need to do is to make webform better instead of abandoning it.

  13. @Jiang: As somebody who has been working with .NET since the betas, and did “classic” VB6/ASP before that, all I want to add is: “You’re wrong.”

    The problem with WebForms is that it is too much of an abstraction, and a leaky one at that. Sure, if you’ve put the time into really understanding the page life cycle, you can get work done. But don’t mistake familiarity for an innate quality.

    MVC and WebForms aren’t going anywhere, we’ll be using both where appropriate for a long time.

  14. @Trasa: can microsoft asp.net team fix the leaky part of webform? Why don’t they fix their stuff before they throw money into something that has already been created in PHP, Java and the like? Take a look at some of the asp.net mvc implementation of theBeerHouse, http://www.codeplex.com/TheBeerHouse/SourceControl/changeset/view/44960#690920

    I have to say that it makes me puke. That code looks ugly, primitive. It looks like the php code I am maintaining and it makes me sick and adding new functionality that usually takes very little time with asp.net webform become a major undertaking with php.

    Please take a look at the thebeerhouse asp.net mvc implementation and tell me that’s the code you guys want to write and maintain.

  15. @Jiang 2: And perhaps I should clarify: If I can find a poor example of WebForms, would that really prove anything?

Comments are closed.