Tuesday, March 27, 2007

Great Intro to Refactoring

This PDF by Thycotic Software is a great explanation of refactoring and unit testing in C#. They took a chapter of Martin Fowler's book Refactoring: Improving the Design of Existing Code, translated the code into C# and added some unit tests.

Monday, March 26, 2007

Video on ASP.NET Databinding

http://blogs.interfacett.com/dan-wahlins-blog/2007/3/25/video-binding-data-to-aspnet-20-server-controls.html

This video from Dan Wahlin is a really good tutorial of a master-detail view. The trick is to use "DetailsView1$dd" as the ControlID in the ControlParameter when updating or inserting. It's not very intuitive and it looks like a hack but it seems to work. I've mentioned my troubles with code-free databinding; hopefully this will set me straight.

Saturday, March 24, 2007

ASP.NET vs. Ruby on Rails

If you're a contracter and you're being paid a flat fee to develop a simple website that basically only collects data and creates reports, what language and toolset do you use? You don't have to every do maintenance and you can't fix bugs. You want to get it done as quick as possible since you're being paid a flat fee. You have the freedom to choose whatever hardware and software you need. Obviously, your personal skill set is important in determining your answer but for me, it's a decision between ASP.NET and Ruby on Rails.

I believe in RoR. I think that it's a great way to build a website, especially one with requirements like these. My main issues involve its maturity, its tools and my familiarity with Ruby. Maturity isn't a problem in itself, but there are other problems that will go away with time, and I see this as an immaturity issue.

There's too much room for error in deployment because I have to TTY into the server and type things into a command line. I also feel like I need to know a lot more about Apache or FastCGI or Mongrel or whatever. I don't trust the RoR tools. There don't seem to be very good IDEs for working in Ruby, largely because Ruby is so dynamic that a new type of tool is required. The libraries are untrustworthy because they're not standard. I don't want to deploy (or even work with) a library with bugs, and I don't know where to find out which is the mature library.

I'm only considering ASP.NET a viable option because of SubSonic. Without that library, I'd spent way too much time writing and debugging data access code. The issues I have with ASP.NET are the inability to create unit tests without bucking the framework and unnecessary complexity of using controls instead of HTML. ASP.NET doesn't do MVC. It has views and no controller, which is quite untestable. Last I used it, NUnitASP was the best way to test it but it couldn't come close to testing an entire site with AJAX and everything else. I've become increasingly uncomfortable with using the ASP.NET controls when they're anything more than thin wrappers around HTML controls. (Except the Login controls in 2.0 which I love. Feel free to stop reading now.) As I rely on them more, I see more side effects and I find that I'm fighting with them or writing code that I feel is like a hack. A master-detail view should be easier and have fewer corner cases.

MonoRail is getting close to usable but it doesn't have a view engine I'm comfortable with. I fully acknowledge that it may be the best option, but I'm going to need to test it out first, and I haven't.

I'd go with ASP.NET. I think it may take slightly longer but it would be easier. The tipping point is RoR's toolset. With ASP.NET, I can use Visual Studio and set up pages using the designer.

Monday, March 19, 2007

Smart Clients and Web Clients

I don't think there's an accepted strategy on the smart client / web client decision. Smart clients are desktop applications that get their data from the internet and have a reputation of being more powerful and easier to use while web clients don't need to be installed and are easier to update. With AJAX, great design and clever Javascript, the web can provide as much functionality as a smart client. Similarly, web services can let smart clients use the same real-time data as well as clients. So which is better?

Let's not ignore the possibility of both. Would it be good if we had a choice? We could use the smart client at our main computer and the web client on the road. Well, if we have a web client, why do we need a smart client? Is the UI so complex that there's a significant advantage to a smart client?If so, maybe the solution is to make the UI simpler. Also, would they work the same? There are toolkits like Visual WebGui or GWT that may let us use the same UI for both clients, but if the smart client isn't significantly better, we may as well not create it. They also don't work very well; the web and desktop aren't the same and aren't easily abstracted away. Throw in the extra work for creating two clients, regardless of whether they use the same UI toolkit, and this is a no-go.

Except for one situation, I'll go with the web client, especially in the long term. Web UIs are simpler and allow for more branding. They're easier to get working for different operating systems and it's the platform that is improving faster. There's Flash if you need a complex UI. The main problem that I see is that good UIs are difficult to create. AJAX is necessary but it isn't an easy concept for developers to grasp. This is slowly being alleviated through new libraries such as Prototype, ASP.NET Ajax and Flex; I believe it's worth putting the effort into the web client and it will be easier to benefit in the near future.

The situation that I'd go with a desktop client is if there's a compelling technology that's not available on the web. 3D is a good example of why games on the web are generally puzzle games or simple action games. WPF is possibly the only technology that makes a smart client desirable, and that's not insignificant because it's a very nice library. I'd say that audio (music) is another thing the desktop does a lot better than the web, but sites like Slacker and Pandora have web-based music players that are pretty good.

In short, I'd go with the web client unless it's prohibitively expensive.

Friday, March 16, 2007

Google Maps and Web Controls

Google Maps is probably the most revolutionary piece of software released on the web in its era. Compare the old map interfaces with a small yellow map, ugly fonts and arrows on each side so you could pan by getting a whole new map. Google Maps uses the whole screen, has pretty fonts and doesn't redraw. It is a tremendous user experience on the web in a time when the web meant the UI was mostly forms. It kickstarted the notion that the web can be as pretty as a desktop client.

At the moment, it still takes a ton of work to get a good user experience out of a web application. There are lots of browser compatibility issues, poor JavaScript editors and a lack of integration with server code to deal with. Libraries such as Prototype and jQuery are beginning to solve some of the issues but these are really just the base of an overall solution. EXT is probably similar to the next generation of web libraries: a layer on top. YUI has both a layer on top of JavaScript and controls using that layer.

Using controls with server code may also be the future. We already have tons of code the runs on the server, as well as the necessary ability to access the database. ASP.NET Ajax is Microsoft's attempt at increasing the web experience and we'll have to see if that can serve as the basis for more projects than the Control Toolkit.

Script# is a very clever attempt at writing JavaScript code with C#. You could even write Vista Sidebar Gadgets with this library. This seems to be a promising avenue but the developer (a Microsoft employee) seems to have stopped development. GWT is a more mature effort to write JavaScript with Java, but I have no experience with it.

The situation will shake out over the next 5 years or so. By 2012, creating a web application with a great UI should be standard. We should have enough research into UI design by then, too. Hopefully the browser manufacturers will cooperate by standardizing their JavaScript and layout engines, but it doesn't seem to be necessary.

Saturday, March 10, 2007

Betas and GAX/GAT

I used to love installing betas and trying out new ways to code. I still enjoy it, but all that time taught me that the same thing will happen after a certain amount of time. The WOW part of the beta will be wonderful and exactly as explained. Continuing to build will inevitably lead to the point where you cannot accomplish what you want. The docs say it will do one thing but the forums confirm that what you need to do is broken and can't be done. Of course, if everything was working they wouldn't be betas, they'd be products.

This mentality has prevented me from installing GAX and GAT. They are Visual Studio 2005 extensions that come with recipes that make it easier to create and use frameworks and thus easier to write code. This is the kind of thing I love, and I made the mistake of downloading and installing it. No joke, and maybe it was a coincidence, but my shift key wouldn't work in VS 2005 until I uninstalled. I wasn't expecting too much and I'm still interested in the technology, but I decided to wait until the final release before trying it again.

The first beta was released in May 2005 and now it's March 2007 and I can't find any release date. This is discouraging. The Smart Client Guidance seems like it would be useful, but I need my shift key.

Thursday, March 8, 2007

ASP.Net Ajax as a Tool

Libraries are abstractions that make it easier to do things that can already be done. Sure, you could write your own code that parses XML files, but it's a lot easier, quicker and more reliable if you use one that someone else wrote. If that library doesn't work correctly or doesn't make the job easier, it's not usable. Flexibility is a bonus. It's useful if you can use the same library for image resizing and image format conversion but if there isn't one, you can just use two libraries. If a library is too inflexible, it becomes usable. A library that takes any image and resizes it to 32 x 32 isn't useful at all if I want 48 x 48.

ASP.Net Ajax is an odd case. It makes some thing extremely easy, and for that alone it's going to get wide usage. UpdatePanels are an extremely easy way to avoid whole page refreshes for minor changes and lower bandwidth usage. The Control Toolkit has a little bit of a learning curve but it's also a great tool to do some useful things on web pages.

It's almost a shame that the javascript libraries are a mess. They are extremely intimidating, and my attempts to dig into it have been discouraging. Javascript is a very lean and powerful language and I have to wonder if there's a benefit of a namespace and class system is necessary. The UpdatePanel and Control Toolkit is built on top of the javascript libraries, so I'm going to have them at my disposal and I may as well use them.

I want to use them. There are problems I'd like to solve that require Javascript and I don't want to bloat my site with more than one library. Specifically, I'd like to go to the server, do some processing, and send back code that modifies one element on the page, similar to Unobtrusive Javascript in Rails. The UpdatePanel is overkill, it will update the entire section. I don't think ASP.Net Ajax can do this explicitly and I would like to write and share an Unobtrusive Javascript control for that library, but I don't know if I will. It seems like it will be much easier to avoid using the javascript library and create a separate library that I would probably not share.

Monday, March 5, 2007

OR/M and SubSonic

OR/M is the easiest way to get data out of the database without writing the code necessary to access the database. You can just use objects with methods like Load and Save. The technology is just beginning to leave its infancy stage and many libraries are difficult to configure and use. NHibernate was the first OR/M that I got working and it provides a tremendous productivity increase. However, you still have to use a code generator to create your objects to start and every time you update your DB. NHibnernate's delays in updating to a codebase where you can use generics and nullables had me looking for a new OR/M. Elementary looks interesting but you still have to generate and regenerate the class files.

SubSonic doesn't have that problem. It's written by the guy who does the Commerce Starter Kit, which I've never looked at but it seems like a good project. It's currently designed for web sites projects and uses a build provider to generate the classes. It also generates classes for views and stored procedures, which other OR/Ms don't concern with because of idealogical problems. The next release will include a custom build tool that will extend this feature to libraries and Windows Forms projects. It's also very easy to use and greatly cuts down on necessary code, even over HNibernate. Subsonic is still getting features but there's an active community.

Microsoft is working on an OR/M called LINQ that looks like it will become the de facto standard. Recent CTPs of Visual Studio Orcas have included it but I haven't used any of them. LINQ is going to have to be pretty good to beat SubSonic.