ASP.NET Is A Leaky Abstraction
One of the things that attracted me to development with ASP.NET as a relatively inexperienced developer were the server controls. They made development a lot like Windows Forms development. Just drag a button control and a TextBox control on a page and double-click to wire up your code to the button. Don't worry about state. Don't worry about input errors - we have more controls for that. It was lovely.
My first experience with ASP.NET was frustrating, however.
My prior experience with web development was with PHP and Classic ASP and having to take the data provided by silly HTML form controls and convert them into a usable state was, in a word, awful. I was, however, in complete control of everything. I could, with a combination of javascript, CSS, and some smarmy HTML, make a web page that would knock your socks off and be small to boot.
My first ASP.NET task was making one of my existing Classic ASP UIs (which worked exactly how our client wanted) and do the equivalent in ASP.NET. To get everything to work exactly as it had, I spent the majority of my time performing the following algorithm:
- Compiling and running my application
- look at the HTML that was output (because I had no idea what a "Panel" could possibly be in HTML)
- Hacking in my CSS and javascript (hardcoding HTML element IDs I prayed would remain the same)
- Repeat
I never got it to look and feel exactly like the original. First of all, it was bigger. A lot bigger. The page size had magically morphed from slender and fit to looking like it needed to visit Jenny Craig. Secondly, because this was Visual Studio 2003 that encouraged absolute positioning, it was littered with lots of inline styles and didn't resize at all. My boss's comment at the time was that it worked exactly as intended, but was uglier. We went with the newer, uglier, version of the application because the performance benefits and the maintenance costs were significantly less.
Your standard GridView demo is great, requires very little programming knowledge, and doesn't require opening the hood to see how this puppy works, but is not representative of what most of us are tasked with creating. You see these demos and you say, "Wow, I wouldn't have to write any HTML to do that, nice!" and then when your requirements come in you say "Ok, now how do I write my own HTML?"
I've spent the better part of the rest of my career, as a developer primarily working with .NET technologies, dealing with this exact problem. I've become successful at it, I believe, solely because I am more willing to roll up my sleeves with tools like Reflector and books like Developing ASP.NET Server Controls and Components and peel back the layers of abstraction. This is necessary to really get ASP.NET to work exactly how you want.
There have been a lot of advances in this regard to try and fix the server control model and allow you to customize the output of the control. The Control Adapter Architecture and subsequent ASP.NET 2.0 CSS Friendly Control Adapters is one such example. These allowed you to get into the guts of the server control and replace its rendered output to something much more custom. The problem with this was you had to know quite a bit about ASP.NET to get it to work correctly and it was and is a time-consuming endeavor.
All of this ignores the fact that essentially there is an intentional disconnect between the control and its output. This is an architectural choice and fixing or allowing workarounds to a fundamental architectural decision only adds corroborating evidence that the abstraction is a leaky one. I wouldn't say that it is necessarily wrong, mind you. It's a very good model and beautifully implemented, but the fact of the matter is that when you want to get into the nitty-gritty, it gets in the way.
You can write HTML in an ASP.NET page - I'm not saying you can't. However, the standard examples and most textbooks do not show you this in great detail and often seem to discourage it.
I think this is turning around, however. With ASP.NET MVC and a few new controls like the ListView Control, HTML is becoming more of a first-class citizen again and not being hidden behind controls and some of the bloat that was necessary on every page is being reduced or removed. I'm looking forward to working with these new tools and not having to work around a model.
Trackbacks
No Trackbacks
Comments
No Comments