The return of MVC

Posted on October 28, 2007 09:23 by Alex

I think I first learned about Model-View-Controller (MVC) when I was taking a Java class at the University of North Carolina.  My professor had a background in Smalltalk, an object oriented language in which the MVC pattern was first developed. The MVC pattern describes a practice of separating the business objects (the model), presentation (the view), and the code that responds to user input (the controller). Or, as Steve Burbeck wrote in a seminal article on the subject:

"In the MVC paradigm the user input, the modeling of the external world, and the visual feedback to the user are explicitly separated and handled by three types of object, each specialized for its task. The view manages the graphical and/or textual output to the portion of the bitmapped display that is allocated to its application. The controller interprets the mouse and keyboard inputs from the user, commanding the model and/or the view to change as appropriate. Finally, the model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller)." (Applications Programming in Smalltalk-80: How to use Model-View-Controller by Steve Burbeck)

When I started developing web applications professionaly (using Java) I did not really understand how to apply this pattern -- nor were there any frameworks available that I knew about (this was before JavaServer Pages). The first application I built was an online store in which I wrote all the code in one servlet. At least I knew enough to create a simple template system so that the static HTML was read from a file and only the dynamic parts were written out in the code. I soon started programming more object-orientedly by creating classes to model entitities and using the command pattern to process requests. I realized that I needed to do a better job separating the presentation from the business logic. When I discovered Struts, an MVC framework for Java, I decided that I would try that out in my next project.  But just as I was starting to figure Struts out, I took a job at Elon University where everything was Microsoft. At Elon all the code I dealt with was in classic ASP, and given my Java background and Elon's investment in Microsoft technologies, it was logical to migrate to ASP.NET using C#.

ASP.NET is basically a framework for making web application development RAD-like, so that web apps can be developed like classic Visual Basic applications where one drops some controls into a form and wires up their events to some actions. How does this differ from MVC?  After all, one of the big advantages of ASP.NET web forms over classic ASP is that the programming logic is put in a separate code-behind file. In a sense, the code-behind, which handles the events triggered on the web form, acts like a controller. It is then up to the developer to create models, either by defining custom classes (which is what I usually do) or by using data objects from the .Net library (e.g. Datagrids). This is definately a major improvement over classic ASP. However, if ASP.NET web forms truly use MVC, then I doubt that Scott Guthrie, product manager for ASP.NET at Microsoft, would have announced the ASP.NET MVC Framework at ALT.NET conference.

I am looking forward to trying out the ASP.NET MVC Framework when they release the first preview early next year. In the meantime, I have been trying out the Zend Framework for PHP which makes use of the MVC pattern. I have not done much PHP programming -- mostly in school over 8 years ago, and have generally viewed it in the same light as classic ASP -- but I have to say I am impressed with the Zend frameword and plan to use it to develop Insipe.com, a side project I am starting to work on. I found Mitchell Hashimoto's Zend Framework Tutorials to be very useful in getting started with it and the Zend Reference Guide is very good for learning the details of the framework.


Silverlight and Expression Studio

Posted on October 7, 2007 11:00 by Alex

This past week a colleague and I attended a Microsoft event on Silverlight and Expression Studio. Given that we will be giving a brief report on the sessions at our weekly staff meeting, I thought it would also be a good idea to also make this the first "real" post to my blog...

The presentation consisted of two sessions: "Building Rich Interactive Applications with Microsoft Silverlight" by Bill Zack and "Delivering Rich Web Experiences Using Microsoft Expression Studio" by Peter Laudati. Bill and Peter are Microsoft developer evangelists. Because there were a lot of questions, most of the time was devoted to the first topic, which was alright with us because that is what we were most interested in.

Silverlight -- despite their claims to being more than this -- is basically Microsoft's answer to Flash. Like Adobe Flash, Silverlight runs as a browser plugin, and is good for displaying vector-based graphics and animations, and streaming video. I don't know enough about Flash to offer a detailed comparison and although I'm sure Silverlight offers some real technical advantages over Flash, I am a little skeptical that it is that much better. The main two claims that it is not just a rival's version of Flash were that Silverlight is a platform for developing real applications and that it supports streaming high definition video (recommended for Intranet environments that can support the bandwidth requirements). I don't know about Flash's video limitations, but I think it is hard to argue that it has not become a development platform of it's own. Still, the advantage of Siliverlight, for me, is that I can leverage my .Net skills and develop in Visual Studio to create Flash-like applications.  Silverlight applications are developed using XAML and Javascript. Also, starting with version 1.1, developers can program Silveright applications in various .Net languages such as C# and VB.NET.

Silverlight 1.0 was released about a month ago and Microsoft is planning to release version 1.1 in the first quarter of 2008. Currently, an alpha version of 1.1 is available for download. There is a Silverlight plugin available for the Mac which they demonstrated by going to hsn.tv on a Mac Powerbook. One current disadvantage of Silverlight is that it does not have as wide an install base as does Flash. Like Flash, Silverlight runs as a browser plugin which must be installed on the client machine. A member of the audience asked why Microsoft doesn't include Silverlight with a Windows Update (which would mean millions of people would automatically download and install it with out most of them even knowing what it is). The answer was that Microsoft would likely have legal (anti-trust) issues by doing that. I am sure that is for the best, but as a developer I will be reluctant to recommend that clients rely on Silverlight until it reaches some sort of critical mass.

Microsoft Expression Studio is a group of applications for designing web and WPF (Windows Presentation Foundation) applications. The first (and current) version of Expression Studio was released last spring and does not support Silverlight. The next version will be released in early 2008 and will support developing Silverlight applications. The Expression Blend application is used for creating and editing XAML, the markup language that is used to create the interface elements for both Silverlight and WPF applications. Expression Studio also includes tools for designing and editing HTML, managing digital assets, and encoding videos. The key advantage for both Expression Blend and Expression Web (the HTML editor) is that they allow web designers and producers to work with Visual Studio projects. This means that the programmers can concentrate on application functionality without having to implement the UI design. This eliminates a scenario that they described, and one which I often encounter: an artist gives a developer a design in the form of a comp image and the developer tries to implement with their tools and knowlege. With Expression, the designer is able to produce the files that are used by the application and the designer is even able to make changes after the developer has worked on implementing the functionality of the application.  Where I work we have web producers who help create the html and css -- but it seems to me that the Expression could help facilitate the process between the developer and producer.