I got a bit sidetracked from the MVC stuff as I didn't have as much time between projects as expected, but had a chance today to play around with it a bit more at home. I don't really have any earth shattering things to share, but I did run into a couple of beginner gotchas here and there. Still not quite wrapping my head around certain things.
I had set up my home machine with Visual Studio 2008, but I guess I never finished setting things up. I had copied my MVC projects over and was having trouble getting certain things to work properly until I realized I hadn't installed the MVC bits yet. Doh. So that helped. I had a couple of the dlls in the bin directory, so a lot of things actually worked, but the Visual Studio tie-ins weren't there. Also, you really can't run an MVC project by opening from the file system, you do have to use the MVC project type in order to get everything wired up correctly. That might be obvious, but if you have gotten used to just pointing at a directory to quickly open a web site to play around with, that won't work.
On my new project we are using LINQ extensively, so when I last played around with MVC I was also trying to figure out LINQ and between the two had a bit of a learning curve. I'm starting to get more comfortable with LINQ, so that helped me get up and running a lot more quickly this time. I figured out how to use the LINQ to SQL objects as a ViewData source for my MVC views, so that is kinda cool. If you want to just spit our html using a for each type pattern, you can even cast the objects back into your LINQ to SQL object and get strong-typing in your view. Not sure if that is kosher or not, but hey I'm still learning. Guthrie does it a bit, so I think I might be safe. You can also use the standard ASP.NET data controls like grid views, repeaters, etc., but that might get you into trouble. More on that later.
My personal web site has a lot of simple pages where I just get and display some data, such as favorite movies, music and so forth. MVC works great for that. In fact, I was able to rewire about 6 pages in an afternoon, including LINQ data access. So that is pretty sweet. Also really like the Html.ActionLink syntax for links, as it gives you a lot of security against moving stuff around. As long as your controllers know where to find the views, the actual view can change as much as you want in location, name, etc. I'm still looking for a good way to use an image rather than text though. People have a few ideas, but this feels like an area that needs improvement.
After getting data display working on a number of pages, the next thing I need to investigate is saving data back to the database. There are a couple of things that are a bit of a paradigm shift here. One, you don't have server controls, postback, viewstate, etc. So in some ways it is a step back to some older ways of doing things, but it gets you back to a very clean html entry form again, but with all the power of the latest .NET stack working for you. Two (and this is the trouble I was talking about), you can't have a server form on the page or stuff just doesn't work. I was trying to follow some tutorials and couldn't figure out what I was missing. Typically you create a standard html form and set it to post to an action your controller understands. Mine was just posting back to the same view and I couldn't figure out why until I realized I also had another standard asp.net form (runat = server) on the page that was confusing things. Once I removed that, I started getting the behavior I expected. Unfortunately, I was at a point where I needed to stop so I'll have to continue that learning curve on another day. Seems reasonably straight-forward now that I'm starting to wrap my head around it though.
So I just rolled off a project I've been on for awhile and I'm taking a few days to dig a bit into the ASP.NET MVC framework, now in Preview 2. Some good material came out of the MIX conference, including a particularly great presentation from Scott Hanselman. If you are starting from scratch, that's a pretty good place to start. You can either download a WMV or watch it streaming. In addition, there is now a whole section on the main ASP.NET web site dedicated to MVC with resources, forums and so on. A lot of other articles and blog posts are starting to pop up as well, so if you are a little intimidated about jumping in there is starting to be some support.
As I've mentioned before, I've been working with ASP.NET since the pre-beta and have mostly kept up with the various changes to the framework over the years. There are aspects of ASP.NET 2.0 that I wouldn't consider myself an expert on, but I at least know the basics for most features and where to find information if I need it. I say that because I expect a lot of ASP.NET developers are in a similar boat with me when it comes to MVC. I've worked on a lot of enterprise web projects, including several version conversions. I've used a bunch of the betas. But I've generally stuck to the Microsoft provided "bits", partly for client needs for maintainability and understanding of code and partly to avoid some of the risk of a new version breaking a bunch of custom or 3rd party code not controlled by Microsoft. So I haven't really dug into the ALT.NET side of things. Played a little with stuff like Cruise Control, log4net, some code generators and so forth. Understand the very basics of TDD, but haven't really found a very good way to do it on the traditional ASP.NET side of things. Anybody out there in the same boat?
So anyway, call me chicken, but now that Microsoft is working on an MVC stack I'm finally willing to take a look. Scott Guthrie has really gathered some good people on his various teams over the past few years and I really think they are trying to do the right thing when it comes to community input, transparency and willingness to try new things. So the MVC bits aren't really even close to done, but they have accomplished a lot in a short time. I think there is still a lot of question about where this fits into enterprise development and what types of applications are best suited to this approach. The types of applications many of us write involving heavy reliance on viewstate, sessions, event wireup and now AJAX don't always map nicely or clearly to an MVC approach. That's not to say they can't be done, but the best practices jury is still out in a lot of cases. That being said, test-driven development maps so nicely to this approach in a way that wasn't possible before, so that alone to me makes it worth a serious look when designing a new web application. Because it really isn't terribly easy to do this with traditional ASP.NET (other than some type of grand automation scheme that still requires a web server), a lot of web developers, myself included, have basically thrown up our hands and haven't really even tried.
There are a couple of other features of the MVC stack that I like a lot. Maybe not features even as much as a philosophical approach. Here are a few highlights:
- Separation of concerns, as Guthrie talks about a lot. Real n-tier development. Mockable interface-driven web sites.
- Extensibility. There is a real effort to include other test frameworks, view frameworks, etc in the flow. Or write your own.
- Routing. This is super cool, allowing you to separate your view logic (think web pages in traditional sites) from the actual url. Create urls your Mom can remember. Move things around without breaking anything.
One more thing, if you want to learn the new language features like LINQ, lambda expressions, anonymous types, etc., these things are all over the place in the MVC framework. And for me, the way they are used really helps me understand the power of these features and how you might use them in a real application. Many of the walkthroughs or blog posts point these out, so it's a good way to introduce yourself to some new stuff.
In an amazing (and unexpected) about face, the IE team has reversed its previous decision on how to implement standards in the next version of Internet Explorer. I was one of many in the community who decried the original decision as backward thinking and just plain wrong, so I'm very pleasantly surprised that they listened to the community. At least I hope that's what they did, although there are various vague rumblings of new interoperability initiatives connected with some EU issues and some other reasons listed. No matter why they did it, making a decision to go full speed ahead with standards will be a boon to the web development community, although there are obviously still a lot of legacy browsers to support. At least we won't have to program for IE8 quirks in 2012 (hopefully).
I'm pretty disappointed, maybe even a bit angry, at the direction the Internet Explorer team has decided to take with IE 8 and support for standards. In this blog post, the team explains all the issues they ran into and how they decided to deal with them. As you can see from the many comments, they haven't made many people happy. For awhile now, they have promised to support the ACID2 standards for web design with the next release of IE. Unfortunately, I don't see any possible way their approach can be considered standards since it relies on a proprietary META tag to force the browser to render according to standards. Otherwise, it either renders in "quirks" mode (I was so over this years ago) or render like IE6 does. Both of these are terrible standards to follow, most if not all web developers would love to see a day when nothing has to be done to work around all the shortcomings of previous IE rendering engines. At any rate, needing a proprietary META tag to pass the ACID2 test is about the furthest thing from standards support imaginable. Just rip the band-aid off already, it's never going to be a good time to undo all the previous bad decisions.
A couple of the commenters rightly declared that they write web pages according to standards, not browsers. This is the right response. As a web developer, I should be able to code to standards and then expect the browser to render in a close enough fashion to standards that I don't have to jump through hoops to get pages to render properly. I can expect this for Firefox, Opera and Safari for the most part, but not IE.
The IE team's excuse is that web developers expect IE to work a certain way and already code their pages with that expectation. Maybe so, but in what universe is that a good thing? I don't think any of us want to do things that way, we are forced to because of the terrible rendering flaws in Internet Explorer. Honestly, most of the pages that would "break" are not being regularly updated anyway, so who cares? Or they are still using tables for layout, in which case IE's problems with the box model have a lesser impact anyway.
I have a couple of alternate approaches (neither of which are original with me). First of all, if you want to use a META tag, have it turn off the full-standards support, not turn it on. The default should be that the rendering engine attempts to render the page according to standards. Maybe if most pages start breaking in older versions of IE, people will stop using them. Sure there are folks who for one reason or another can't upgrade, but those aren't your power users anyway. Technology runs on progress, deal with it. Second, why not check for a valid RECENT DOCTYPE instead. Most developers using a DOCTYPE are using it intentionally to force IE out of quirks mode. So this type of page is probably already going to render in a standards-based browser without too much problem. If the page doesn't have a DOCTYPE, fine, go ahead and render it with all the IE rendering issues intact. But otherwise, render it correctly.
I don't have much faith that the IE team is going to do the right thing. I'm beginning to think that most of the web developers complaining about Microsoft's arrogance around standards is right on the money. Still, there are definitely people at Microsoft that care (Guthrie, I'm looking at you) and there are certainly enough developers that care. So do the right thing and finally fix IE so our children can live in a world where web design is full of happy little clouds and strawberry fields.
I was finally able to complete an upgrade of our blog software to Community Server 2007. In past versions, I had to write custom code to support what we call "global categories". These were categories that any blog on the site could use. With the new tag-based system, this is no longer necessary.
The major work was in learning the new theming system and creating a Clarity custom theme. The new theme engine is fairly easy to use once you get the hang of it, but there is still a bit of a learning curve. Still I do think it is easier than before.
I've been using Community Server 2007 on my personal blog for a few months now and I'm glad we can start using it for Clarity Blogs. There are a lot of little fixes and enhancements that make it a really nice update.
I ran into a very interesting find the other day while trying to optimize some queries by studying the execution plans. We have a bunch of stored procedures that use an underlying view that points to a single table. This table has an "item_id" key and often we use that key in the WHERE clause or for joins.
As there was an existing clustered index on that column, I couldn't figure out why I was always getting table scans on the underlying table. In other words, the query engine was completely ignoring the index or deciding not to use it.
I ran a simplified version of the query with the item_id hard-coded and all of a sudden it did use the index, giving me a huge performance boost because the table is a bit large. Not millions of rows large, but relatively large for our application. That got me thinking about datatypes, so I decided to check the underlying table. Numeric(8,0). Hmmm. We are using int everywhere. Surely that is a simple enough implicit conversion to not cause issues, right? Wrong. Once I changed my input parameters on the stored procedures to use numeric(8,0) instead of int, I started getting nice clustered index seeks everywhere. Bingo. I've seen this type of thing before, but generally it is a more drastic conversion or comparison like datetime vs varchar or int vs char or something like that.
Anyway, another weird performance tip that is certainly not intuitive. This is on SQL Server 2000, not sure if the same behavior exists in SQL Server 2005 or newer.
Over the last few months, I've been seeing a lot more about web application frameworks using the MVC pattern, as well as rumors about Microsoft working on some sort of framework to support MVC in ASP.NET. There are already a bunch of 3rd party tools that people are using, particularly MonoRail. My gut is this is partly a pattern that people who like clean separation of layers and TDD can get behind, which traditionally has been difficult in traditional ASP.NET coding patterns. And partly a response to Ruby, something which I confess I have not had time to learn much about.
All this is particularly interesting to me since I've been working on the ASP and ASP.NET stack for quite a long time now and there are certain things that have always been difficult, such as automated testing and breaking up applications into smaller chunks that can be deployed and tested independently. And then there's always the presentation vs the business layer vs the database layer stuff that continue to need refining. And provide something for architects to fight about.
I have to say this pattern represents a pretty big shift in thinking for an old school web app guy like me, but I am starting to see some of the positive aspects of it as I look into it. It doesn't feel right for every web app, although that might change once I build up some skills using an MVC pattern.
Anyway, apparently Microsoft was a bit further along than I thought, as early demos popped up at the ALT.NET conference from a week or so ago. If you don't have time to watch the video stylings of Scott Hanselman of ScottGu's lecture, ScottGu has also posted a really good overview on his blog earlier this week. I think it's something we'll be hearing a lot more about and I'm curious to learn more about how to best leverage this approach.
Well, I realize I haven't posted in awhile. The process of getting married tends to eat up a lot of your free time, although it is fantastic and well worth it. On top of that, my current project has slowed significantly for a variety of reasons, including the lead dev moving on to another part of the company and delays in getting our current main focus deployed. One thing I will say, once other people become dependencies in a project, all bets are off. We've had delays from people leaving, delays waiting for people to test, delays in getting code deployed due to resource shortages and delays in code other people are working on. That's corporate development I guess, but it tends to be at odds with the kind of code output a typical Clarity project team can do.
Ajax continues to be interesting, but the more I work with it the more I realize although Microsoft made some things simple on the surface, it isn't quite as simple as it appears in the context of an enterprise application. There are a lot of considerations to take into account, particularly when it comes to the interplay between client-side and server-side objects and code. There is a bit of a mind shift that has to take place and as long as you keep a foot in both worlds, a lot of decisions are not as straightforward as they could be. Silverlight may end up confusing matters even more. It's an awesome time to be involved in web development, but now more than ever you really have to stop and think about how you are going to manage and architect a solution.
When I have downtime, I've been doing some code refactoring and FxCop has turned out to be a pretty cool tool for basic stuff. I haven't looked into any of the custom rule sets yet, but apparently you can now share rule sets up on GotDotNet, although GDN is being phased out so not sure where it will end up. Also updating some documentation with Sandcastle, Microsoft's replacement for nDoc to generate xml docs. Right now it's still command line and with all the options, you might want to use the Sandcastle Help File Builder from Eric Woodruff. Feels pretty much like nDoc.
From time to time I have a need to vpn into our Clarity internal network, mostly when I'm upgrading something to do with the blog server or occasionally doing some work from home. I recently upgraded to a new Apple MacBook Pro running Vista, which rocks for the most part. Last week I tried to connect to VPN as usual and no go. Would try to authenticate and fail. Every now and then it would connect briefly and then drop off. So naturally I assumed I had something misconfigured on my laptop and went through the usual litany of troubleshooting (dropping and recreating the connection, applying patches, etc.). No joy.
So over the weekend I had some more time to research the problem and I really wanted to get on the network to install some updates to the blog server. After the usual Google rabbit trail of trying variations on searches for the error I was getting (629 for those keeping score at home), Vista VPN, etc, etc I started to notice my router name was popping up occasionally in the searches. So taking a different tack, I remembered my router was a fairly recent acquisition and maybe I hadn't really tried to VPN since setting it up. Searching on VPN and Linksys WRT54G brought back an onslaught of customer complaints, blog posts, forum posts and various and sundry attempts to get this router working with a standard Windows XP or Vista VPN. To make matters more confusing, Linksys has issued at least 7 versions of this router and I have Version 6. This is a very popular router and one of the de facto choices for wireless G at home, even among techies.
Because Linksys has been rather poor in actually designing firmware that works well, a cottage industry has sprung up around 3rd party firmwares for this router. It's just a modded Linux distro, so obviously the hacker community didn't have too much trouble coming up with something that worked. In additional to working, all kinds of new functionality was able to be included which turned this $75 router into something more like the $3000 routers Cisco, Linksys's parent company, makes bank on. Needless to say, Cisco was not amused and effectively tried to cripple this router starting with Version 5 by limiting the flash RAM to something very small (I think 2 Meg). You can still get very workable 3rd party distros, but you have to be careful to get the right one because if you overrun your firmware space, you might end up with a nice doorstop instead of a router. Actually, a crappy doorstop since these things don't weigh much.
Linksys for some reason can't see to get VPN working in these routers and apparently this problem has existed for at least a year and a half and through several firmware upgrades. So rather than wait for them to fix the problem, I decided to take the risk and plunge and put a 3rd party firmware on mine. I won't go into all the nitty gritty details of it, but I basically followed these instructions, using the DD-WRT distro. Didn't really run into any issues and had the router back up in less than 10 minutes. VPN connected flawlessly and almost instantly the first time I tried. In addition (and this is just anecdotal), the connection seems to have better throughput than before. I still have all the features that the Linksys firmware had and a bunch of extra stuff, which I may or may not use. I haven't lived with this for more than a couple days, so maybe I will run into some things and I'm still not sure what the uptime will be (I was having to reset my Linksys quite regularly). But I'm pretty happy I took the chance at this point.
Joel Spolsky raises a great point about the Windows Vista "Off" button or whatever it is. What a pain in the butt this thing is. I don't need all these choices. All I really want is a) shut my computer off b) i'm closing the lid, so sleep or something until I want to work again and c) i'm leaving my computer for a bit, make sure nobody gets into it. The rest of this crap is just painful to use and get to quickly.
Choices = Headaches — I'm sure there's a whole team of UI designers, programmers, and testers who worked very hard on the OFF button in Windows Vista, but seriously, is this the best you could come up with? — Every time you want to leave your computer, you have to choose between nine …
Source: Joel on Software
Author: Joel Spolsky
Link: http://www.joelonsoftware.com/items/2006/11/21.html
Techmeme permalink
[Via Techmeme]
ASP.NET AJAX B2 just came out, that didn't take long. Probably won't install it right away since I had to pull some teeth to get B1 installed on prod servers. Of particularly interest to me is that UpdateProgress changes have been moved into the core dll now (which means UpdateProgress hooked to a particular set of update panels is fully supported now). Also, the AutoDegrade stuff looks interesting, based on browser it will flip to full postback mode if the browser can't use the AJAX stuff. I'm curious how it does this and if you have to do anything special in the server-side code. Also, that Control Toolkit is starting to look pretty impressive, lots of stuff in there.
Soma announced today that beta 1 of Visual Studio 2005 SP1 is out. Looking forward to this, although I doubt I'll install the beta. We've added a couple of hotfixes, but are still experiencing a variety of issues with VS 2005. Plus it will be nice to have Web Deployment projects and Web Application projects directly included in the product.
It's been interesting to watch the news, both external and internal, around Ray Ozzie's rise to prominence at Microsoft and this month
Wired weighs in on the subject. It's a pretty good article and fairly objective, considering Wired's often anti-Microsoft bias. While everythng I've read about Ozzie would indicate he's an effective leader and gifted technologist, this just seems like more of Microsoft's cult of the individual visionary. And that premise seems increasingly outdated in the current business climate. Don't get me wrong, companies need gifted leaders with vision to effectively implement their ideas and be successful, but I have a feeling that one person can only do so much to turn around a company the size of Microsoft. The culture is strong there, my friend, and not easily changed. And unfortunately some bad habits have crept into the mix, along with a bunch of unnecessary middle managers. However, there are still a lot of smart people there who want to see the company continue to grow and change for the better, so it will be interesting to watch what happens as Gates begins his withdrawal from the day to day operations of the company. The article isn't on the web site yet, but I would suspect it will show up shortly.
On my current project, we had the majority of our ASP.NET 1.1 to 2.0 conversion completed by the time the Web Application Project add-in came out. We made a short attempt to convert our solution back, but we had already made a number of architecture decisions based on the new web site project type. We've had a number of issues with references and ambiguous errors when we choose "Rebuild web site", so we've been doing a Rebuild Solution every time and it has gradually just gotten worse and worse in performance when "building" the web site. If you are getting ready to do a large web application conversion, by all means just start off using the Web Application Project. It will ship as part of VS Service Pack 1, but you can download it separately (fully supported) now. This works much like VS 2003 and integrates better with source control, deployment is more intuitive, etc. You do miss out on a few of the nice features of the new web site "project-less" model though.
After a lot of frustration, we finally set up a meeting with Microsoft to figure out what we could do differently and if we were missing anything. Turns out there are a couple simple things to keep in mind that make this process a whole lot less hassle. Here is something to keep in mind with the new web site and compilation model in ASP.NET 2.0 and VS 2005. There is NO output from the web site if you choose to build it. Everything happens when an HttpRequest is made for the page. In fact, this is what Visual Studio is doing during design time. When you open an aspx codefile in VS, that page is basically requested from the ASP.NET hosting process running inside VS 2005. This is how you get errors in your task list, partly how Intellisense works and why sometimes when you load the page class file you initially get a bunch of "squigglies" indicating errors until the background threads confirm all the references still work.
In the early betas, there was no Build Web Site command at all, only a Validate Web command. The functionality of this command never changed, just the naming because early feedback indicated developers had no idea how to work with a web site they couldn't "build". I remember wondering this myself. So really when you bulld a web site, in effect you are really saying "Go out and validate that I will be able to compile when I decide to run this page in a web browser". Which of course takes just as much time as an actual binary build because all the references have to be checked and a test "precompile" done on every page, control and class.
Here's the trick (or really just how to properly configure your project) to get around this behavior. Open the properties window of your web site (right-click) and go to the Build tab. If you typically run your web site when developing by using F5, set your Start Action (F5) to "No Build". Also, uncheck the box that says "Build web site as part of solution". Now if you do a Rebuild Solution, all you are doing is building whatever other assemblies you have in your solution and copying those outputs, as well as any dlls you have referenced using file references to the \bin directory. Dropped the time it takes our project to do a Rebuild Solution from 2-4 minutes down to 10 seconds. Nice.
Here's what you lose. You won't get a list of all the errors that currently exist in your web site. So you won't know there is an error on the page unless you have it open in Visual Studio or you try to run the page in a browser and it fails to compile at runtime. For me, this is a reasonable tradeoff during development. You will still need to "build" the web site if you are using the Web Deployment Project, but you can do this only in your "Release" configuration where you actually want to output the site for deployment.
Kristin and I raced up the Oregon coast to get to Cannon Beach for the sunset. It was rather otherworldly with the mist and pink light. Check out my Flickr photos for more.
More Posts
Next page »