The Ugliest Part of MVC

by Krishna on August 4, 2009

All the mainstream technologies have converged towards MVC as the primary architecture for web development. One major holdout was ASP.NET WebForms, but that will decline in time with ASP.NET MVC gaining more popularity. This is a good thing for the industry as it will help programmers move to another platform as the general concepts are similar.

Most people will agree that MVC has done a great job of partitioning the codebase so that it is more maintainable. This is especially true at the Model and Controller levels, where increasingly we are writing boilerplate code and linking to libraries that can make the job easier. However, the View layer still need a lot of baby sitting.

The View contains HTML, JavaScript, CSS and program (Java, Ruby, C#) code mixed together. To be very picky, yes, the JS and CSS code may be in separate files, but they are still very much part of the page. And there is overlap between these technologies. You have the traditional use of HTML and CSS for visual display, but JavaScript is also increasingly used to manipulate the DOM. And you have the program outputting data and HTML elements onto the page.

There are, as one would expect, best practices that one can follow. And tools like jQuery are fast becoming standard. But there is no dominating consensus in the sense that this is how each technology (HTML, JSS, CSS, code) should be used. And hence, I would posit that the View is the ugliest part of MVC and will need more time before we see people agreeing on how they should be designed.

P.S. This post was written as I unsuccessfully searched for a book on views. I see many books on MVC itself, particularly on the frameworks (Ruby on Rails, ASP.NET MVC, Struts, etc.), but none on designing Views themselves. There are many books on HTML/CSS design, but these seem to be written by web designers, never by general-purpose programmers. The MVC books talk about creating views, never about designing them properly. A market demand waiting to be fulfilled. But maybe I missed some. If you know any good books on frontend design with MVC, please add a link in the comments.


Aaron August 5, 2009 at 12:15 am

I agree. Views them selves have the 3 parts. The content, how it looks, and the behavior (javascript). Im glad to see rails 3 is starting to go in that direction with its ajax implementations.

Luciano August 5, 2009 at 2:34 pm

Normally the design of the view depends on the "view framework" you want to use. These "view framewoks" usually comes with its best-practices. So, considering that view is the most flexible part of MVC, I really don't know what you're missing. Frameworks as Languages are different, they implement concepts in their way, according with its capabilities. There's no one-solution for all cases. A view could be html, json, txt, flash, xml...

Krishna August 5, 2009 at 4:56 pm

Aaron and Luciano, thanks for your comments.

Luciano, my point was that since the View is flexible, it also tends to be the ugliest part, since the other parts of MVC have more straightforward code. And although we have best practices, there seems to be more freedom to do whatever you want to, which leads to all kinds of ways of doing things. I was not referring to Flash/Silverlight, though they have their own challenges.

Luciano August 5, 2009 at 5:46 pm

Ok. The View is ugly by nature and MVC is just an attempt to minimize this, by organizing part of the work. Minimize! Anyway, there's no technolgy good enought for bad developers and we'll always see horrible things in code. While a View could be (and has to be) in various formats, I just think there's nothing that can be done to solve this.

Krishna August 5, 2009 at 6:10 pm

Yes, you cannot help bad developers from misusing anything. I suppose as things evolve, things will become more standardized. Right now, well...

Comments on this entry are closed.

Previous post:

Next post: