Friday, April 04, 2008

Why ASP.NET is a rip-off.

Every so often, I consider setting up one of my home/toy websites in ASP.NET. Right now, most are using Ruby on Rails and I'm actually running one of them on ASP.NET on Mono on Linux. So I've been known to buy some Windows hosting here and there for some experimentation with ASP.NET.

Why do I never follow through with it? Because ASP.NET is a rip-off.

I've written a bunch of ASP.NET sites at work (mostly web services). At work it made sense to choose ASP.NET because C# is our main tools language, we have a lot of expertise with it and our main platform is Windows. But after a few years of this, I've concluded ASP.NET not made for any kind of sensible web development without those requirements.

Here's why, in a nutshell, that it sucks: ASP.NET was originally designed to try make everything stateful. Just about every problem I have with it is related to design decisions that try to shoehorn that mantra into place. Trying to configure gridviews to sort properly and connect those up to the proper place, etc. Spend about 5 minutes playing with ASP.NET and you'll see what I mean.

The other day at work I was trying to do this, very, VERY simple thing:
  • Query database on page load
  • Set a protected variable on the page to display the image or not
  • In the ASPX code, if my variable is set to true then show an image
That's all. But after mucking around with trying to figure out which Page Event to put the database query, how to structure the <% %> code, and whether I could use <%# Eval() %> in CSS, etc., etc. I finally gave up and used and set the visibility flag directly on that control in Page_Load.

Why is this a colossal failure of ASP.NET, you might ask? Because it required throwing out a trivial chunk of HTML templating that I've been doing for years with the likes of Clearsilver and replacing it with a deep C# class that probably added far more overhead than possibly required for this task.... and introduced a silly controller dependency on the view code to boot!

Another case in point, has anyone ever been able to use Sql/ObjectDataSource for anything beyond trivial queries? It looks like some of this stuff has stellar caching mechanisms... if you're doing the most trivial SELECT statement ever seen. After buying books on ASP.NET, reading all over the web and such, I've concluded that if you want to use ObjectDataSource seriously, the only way to do so is to subclass it.

Don't even get me started on viewstate, by the way. Viewstate is evil and ridiculous.

So frankly, I have no idea how sites like MySpace or Microsoft themselves do it -- how do they actually manage to run a site that large on ASP.NET? It's a mystery to me. The only way I can imagine making those sites work is writing custom HttpHandlers and doing all of the processing in my code, completely throwing out WebControls, DataSets, etc..

At which point I'll have replaced everything about ASP.NET except for writing it in C#.

Although, MySpace has Viewstate turned on for their front page, so I guess they've figured how to make some of this stuff fast... for now. Performance wise, it appears things are getting worse with every .NET Framework release. Google around for "linq performance" and you'll see some reports that the future of data binding in ASP.NET takes upwards of 500% longer than plain old DataReader.

All I've heard is how spectacular Linq is -- and I agree it's great for XML queries -- but it isn't at all straightforward to use and certainly 5x longer queries is unacceptable. But you never hear about that. You see, Microsoft's got a new Visual Studio and a bunch of books to sell you and "MVPs" on the MSDN forums are busy trying to get their "answered your question" votes rather than give critical feedback on deep problems with this stuff.


Jeff Atwood had a very good point about a year ago where he said that choosing a language often means choosing a platform. C# is pretty solid and a fast language, plus Visual Studio is a very nice IDE for editing this stuff. 2008 has great Javascript editing, probably some of the best I've seen.

However, choosing C# means you're choosing ASP.NET as your platform. And let's see what you're into once you do that. You've got development tools at $700 a pop, plus $350 upgrades every other year. Every host you want to set up requires at least a $350 Windows Server Web license. You'll probably run your database on Windows, so that's a couple thousand in licenses, easily.

All that cash for something that, at least in my experience, doesn't make anything easier.
Unless I've got a bunch of C# I need to use, did all of that money spent make development faster or better? No, it won't. And that's why ASP.NET is a rip-off.

No comments: