Ask a Jedi: MVC too much work?
Darren asks:
I've been doing some reading into design patterns specifically mvc, it all started as I got into flex, it all seems a bit scary as well , i've never thought about it for coldfusion and as I come from a design/flash background i've never had any formal programming training, i'm just self taught. I guess i can see the benefits of code reuse but it seems alot of work for normal websites, where do you sit on the issue, do you use design patterns at all. Do you think its worth learning, most of the time I work on my own or with one other person so I don't have large development teams to worry about.
I don't know Darren - can't we discuss something less controversial like politics or religion? ;)
This comes up from time to time in discussions of using a framework. Obviously if you are building a guest book (remember those?) a framework may be overkill. But one thing to keep in mind is that - at least in my experience - very few projects move from complexity to simplicity. Most projects start simple and grow in complexity. With that in mind - I tend to always use a framework like Model-Glue to help me manage the complexity.
I'm very much pro-framework for this reason alone. Having the framework help me organize and set up my application means I'm thinking less about crap and more about business logic.
So to focus on 'is it worth it for normal web sites', I'd say absolutely yes. Is it worth it for a 2 page application on a brochure-ware site? Nope.
Comments
I should say that I am a huge proponent of MVC frameworks for HTML based web applicaitons, and while I do see the benefit of an IOC framework like ColdSpring, I'm not sure I see the benefit of an MVC CF framework behind a Flex app. Any insight would be greatly appreciated.
We have a Flex Application that acts as our content management system for our customers.
On the Search Engine Friendly side of things, we display the content added through the Flex Admin in CFML.
On the Flex side, we used Cairngorm as our MVC.
On the CF side, we found that we needed some small framework to manage the ever growing complexity of the code. It was easier for us to roll our own, because there weren't enough views to warrant a full MVC framework, but there's enough logic to warrant an organizational structure that saves time moving forward (using cfsavecontent pretty extensively).
So, here's my 2 cents:
If you're using nothing more than CFCs for the Flex application, consider strongly a Domain Model. A basic domain model that emulates the hierarchy of your viewstacks in Flex is a good place to start. This kind of organizational structure helps.
If you're using Flex to generate content that is part of a large CMFL system, a standard MVC framework may be very useful.
If you have a couple of pages of content, some contact forms, and a few display pages in CFML, I'd suggest creating your own micro-framework that focuses more on separating logic from layout, and creating complex layouts through smarter and more encapsulated CFCs. You'll also find that you can create more Search Engine Friendly URLs with a homegrown framework, and there's less processing overhead that may be beneficial when it comes to speed (and subsequently, the Search Engine Benefits of fast load times).
I believe Fusebox and Model Glue allow easier integration with Flex Remoting calls, and Model Glue has an example showing the Flex MVC and CF MVC frameworks together.
It's a little more work up front, but it saves tons of time in the long run.
We built our contact form in Flex using the Cairngorm MVC. The benefit is that we could resuse the same form validation, services, regex, etc, as the monster Flex apps.
We used our own homegrown CF framework for populating the Object/Embed/History Manager/JS code because many of our pages use little Flex widgets.
In the future, I think you'll see more robust CF frameworks that are used to serve up Flex and Ajax systems with fewer views, more JS files, and help to create greater structure of the business logic with a completely different take on the "V" from "MVC."
I agree :) , I just haven't taken the plunge into Flex yet. All of our sites are AJAX/HTML for the most part and they work great with FUSEBOX. When I do start our FLEX stuff I will definitely look into Cairngorm (I have read about it already).
Isn't there a Model-Glue flex framework also?
There is a Model Glue framework for Flex that provides an example of using MG for Flex with MG for CF.
sidenote: I'd like to see the CF Frameworks take a slightly more aggressive role in separating out some of the logic required to use the Ajax frameworks.
For ColdFusion, I will require a minimum of not having SQL in the same file as HTML. Once you can break that cycle, moving up to a framework or MVC gets much easier.
One last point...the "known frameworks" were once unknown frameworks. I should write a song about that.
a) An existing framework has the benefit of having been tested in the real world (most likely)
b) Before you re-invent the wheel, maybe you can modify an existing framework
c) There is a difference between having a home grown framework no one knows about and a framework you share with the world, get feedback on, etc.


I like fusebox myself, sites grow fast when ya can see what code exists