Brazilian waxing, choosing a JavaScript framework and why I don't like ASP.NET AJAX

Let me first clarify something. As Jan pointed out I am into Brazilian waxing but please, all you pervert guys stop sending me emails with questions about the subject!

Now that's taken care of, we can get to the matter at hand. A couple of days ago, somebody asked me what the best JavaScript / AJAX framework is to start a new web application project. Because we work mostly with Microsoft technologies the answer should be obvious: ASP.NET AJAX. But I have been working with ASP.NET AJAX for the past few months now and I really don't like it. The first problem with ASP.NET AJAX is rather well known throughout the community: the UpdatePanel. I have found a good article which explains why the UpdatePanel is evil. I would recommend not to use it. It plain sucks. The second fact that I hate about ASP.NET AJAX, including the control toolkit, is the fact that you are cluttering your HTML code with all sorts of custom server controls. I don't want clutter in my ASPX page, I want it to be as clean as possible (thank you ASP.NET MVC). I want my JavaScript in a separate file so I have a clear distinction between presentation (CSS), markup (xHTML) and behavior (JavaScript). I know you don't have to use the drag-and-drop method and that you can use the same ASP.NET AJAX classes in JavaScript, but doing this is painful because documentation is lacking.

These things don't stimulate you in becoming a better (web) programmer. In order to be able to solve the problems you encounter with your software, you have to know how stuff works. It doesn't pay off to be able to open a designer, drag and drop some server controls on it and then wrap them in an UpdatePanel to create a web page using AJAX. You are missing out on a lot of exciting stuff that you encounter when doing client side web programming. You are missing out on JavaScript, a whole new and exciting language. When learning a new programming language you once again have a way of doing things differently, you can see how the new language tries to solve the same problems in comparison to other programming languages and learn from it.

I know it is possible to reference the MicrosoftAjax.js file directly, and write out object oriented JavaScript. Most of the literature mentions that this is possible but very few really go into the matter.

If you compare them to the other JavaScript frameworks out there, jQuery, prototype (with scriptaculous), YUI, ... Documentation is abundant and these frameworks don't try to give you the drag-and-drop experience. They just give you a decent framework, which is necessary with JavaScript, to start enriching your web pages. On wikipedia there is a comparison of the different JavaScript frameworks and ASP.NET AJAX isn't even included! I think that says a lot about the popularity and usage of ASP.NET AJAX.
So before choosing a JavaScript / AJAX framework, don't go blindly for the Microsoft solution. It's not the best around, try out the different frameworks and take the one you like. I have been using AjaxPro with prototype for my personal projects but development of AjaxPro has stopped. For new projects I am going to use ASP.NET MVC, which is great by the way, in combination with jQuery. Chad Myers has a very good how to on the matter.

To conclude I would like to share the different books I have been using/reading about the matter:

51XWseT1BbL._SL160_PIsitb-dp-arrow,TopRight,21,-23_SH30_OU01_AA115_51OY5KP5ydL._SL160_AA115_  416ConPucQL._SL160_AA115_ 512OlKc-kUL._SL160_AA115_ 

I'll probably be writing a review on one or more of these books, although I'll first have to write about the pussy way of development like I promised Patrick.


Comments

June 2. 2008 03:37 AM

Great topic, as it becomes more and more crucial choosing the right and most robust framework for production projects. I have been using jQuery for the last few months and it has been a real pleasure.
My hatred against Javascript suddenly switched over to a fondness, as it now feels more and more like the right competitor for my 'actionscript-addiction' Smile

Pieter Michels

June 2. 2008 07:51 AM

Pingback from alvinashcraft.com

Dew Drop - June 2, 2008 | Alvin Ashcraft's Morning Dew

alvinashcraft.com

June 13. 2008 03:46 AM

ASP.NET Ajax may not be perfect, but I don't think it's as bad as you think.

Yes, to refresh an UpdatePanel you have to go through the whole ASP.NET lifecycle. But that's how ASP.NET has always worked. Every postback results in rebuilding the whole page. But if you're smart about using ViewState, it shouldn't that big a problem. As with any framework, you have to understand it in order to know how to use it properly. Any framework can be used for evil if you write bad code for it.

Another advantage of ASP.NET AJAX is that existing ASP.NET developers don't need to pick up an entirely new skillset. This is an advantage in a fast-paced, constantly changing environment such as my workplace. We don't have time to learn all that javascript and get into the mucky details. We just want to throw UpdatePanels on the page and call it a day. Call it laziness; I call it using time effectively and not reinventing the wheel.

The argument can be made that ASP.NET developers don't know what's going on underneath the hood. True, nothing is forcing them to learn the framework and use it effectively. The same can be said about any framework that contains abstractions. But pretty much the majority of enterprise-level frameworks abstract the details away. The problem with your approach is, if you're forced to learn all the details of how a framework functions before you can even start using it, you'll never have time to actually start using it. At least this is the case where I work.

Regarding your comment about "cluttering your HTML code with all sorts of custom server controls." In my view, one of ASP.NET's major strengths lies in the ability to abstract away from HTML completely. In my ideal ASP.NET application, I would like to see NO HTML WHATSOEVER, only controls. Controls are reusable components; controls can be given behaviors and properties; control rendering is cross-browser compatible. Even in this day and age, cross-browser compatibility is a big enough issue that I always avoid writing my own HTML and Javascript whenever possible. It's just not worth my time as a developer. I've been doing web development for years: HTML, CSS, Javascript when I needed to, PHP, Perl, and most recently ASP.NET. Let me tell you: I'm sick of it, thanks to cross-browser issues. I'd rather let the folks up in Redmond figure it out for me just to avoid the headache. Good riddance. RIA frameworks such as Flex and Silverlight excite me much more than HTML/AJAX based frameworks, just because they get me away from hacking cross-browser problems.

I do agree that it gets confusing when HTML, Javascript, and Controls all get mixed in. Where is the behavior in the code? Is it in the codebehind? In another class somewhere? In the HTML markup? In a javascript event? In an external javascript file? In framework-generated Javascript? Holy cow. So if you're going to choose between pure HTML/JS or ASP.NET controls, try to keep it purely one OR the other.

David Butler

June 15. 2008 08:45 AM

Hey David,

I disagree on several points with you. The point of AJAX is that you only send a small part of your page back to the server, why mess that up and send a bunch of stuff back that is actually not needed? Stuff that uses valuable resources?

The problem with ASP.NET and ASP.NET AJAX is that it abstracts away vital concepts of web development. Concepts you have to understand to build, easily maintain and debug a web application. All goes well as long as your ASP.NET application runs like it should, but when it starts misbehaving you lose a lot more time debugging the thing when you’re only used to dragging-and-dropping controls on a web form. You can’t control your application, ASP.NET generates the HTML and Javascript and so controls what your application outputs.

I don’t mind that cross browser issues are being solved by frameworks, that’s the way it should be. Cross browser issues are a real pain in the ass and not of this time. But the way ASP.NET tries to solve it is not the way in my opion. Frameworks like jQuery also take away the burden of cross browser targeting but without trying to abstract away essential concepts of the web. You still have to deal with JavaScript, with AJAX calls and stuff like that. These are essential parts of web development. When you've got a bug in your application, you can dig into the JavaScript and sort out what the problem really is. When your ASP.NET AJAX Control throws a bunch of JavaScript errors at you, you’re stuck.
You don’t even need a bug to realize that controls aren’t the way to go. I have tried on several occasions to use one of the ASP.NET AJAX Toolkit controls, but I always ended up throwing it out of my application and just write it myself in JavaScript, with the support of the MicrosoftAjax.js file (which is nothing compared to jQuery, ... did I mention I like jQuery?). Because they behaved slighlty different than my client wanted.

About the HTML code, I don’t want ASP.NET to abstract away HTML completely. HTML is the basis of the web, why would you want to abstract it away from a web developer? Do we really want to go to a situation where a web developer has no idea of HTML and just drags and drops controls on the page? What happens if something goes wrong or if we want different behavior from these controls?

If we let the folks up in Redmond figure stuff out, we would all be surfing with buggy Internet Explorer 6, using things like SmartNavigation and GridLayout. Microsoft specific attributes, that only work in their browser and clutter up our html code that we have to maintain. Who knows, we’d even be building web applications using table based layout!

I don’t understand why a developer wouldn’t want to learn new things like JavaScript, I think it’s exciting to learn a new way of doing things. And it doesn’t always have to be the newest thing from Microsoft. We Microsoft developers tend to only learn the things that come from Redmond, stuff like WPF, WCF, Silverlight and so forth but adding a new programming language to your arsenal of tools just makes you a better, smarter programmer. It gives you a fresh view on things and in the long run I’ll always choose personal development over laziness (although it’s very tempting Wink). I understand that in a business environment things always have to go fast and be ready by yesterday. But It’s part of the responsibility of the developer to educate our clients / managers to point out that going that extra mile and learning something new will also benefit them in the future.

Peter

July 4. 2008 04:07 PM

Pingback from elegantcode.com

Elegant Code » Dutch ALT.NET User Group

elegantcode.com

Add comment




  Country flag

biuquote
Loading