Simplicity vs MVC

I learned coldfusion from a “need to know” “get it done now” perspective. Only recently have I truly explored different ways of doing things in CF.

There seems to be 3 distinct methods used by CF developers and I would like to hear thoughts about which are best practices vs expedient vs overkill, and what you prefer. For discussions sake imagine you are building a simple contact book/db (names, address, email, phones).

Set up 1) Sloppy but it works.
Create database table with all fields necessary.
Create a couple of CFMs with Forms that read, insert, update, delete records to the table. Some javascript and CSS. May have redundent code within cfms. Lots of code per CFM page. Data requests may loop back over page or goto next page instead of using AJAX or data binding methods. Minimal number of pages within application.

Set up 2) reusable and semi-modular.
Create database table with all fields necessary.
Create modular CFMs which reflect the Form, cfc’s to do the server side work, some javascript to output records and to do input validation. Use of cfincludes to reduce redundent code. CSS and Javascript are imported/linked pages. Reduces page code volume but increases number of files in the application. Some use of Ajax and Data binding for real time updates.

Set up 3) MVC + JQuery
Strong client side programing with minimal calls to the server for data.
Heavy use of JQUERY, AJAX, DataBinding, Structures, ResponseObjects, etc… Use MVC architecture to truly modularize code. Code volume is minimal per module. May use XML or flat text file in place of database.

I’m currently into the reuseable and semi-modular setup.

Started getting into rails and came back to cf with new thoughts on how things should be set up. I think I’m using cfc’s WAY more efficiently now. I still like how ruby sets up methods better, but cf is still my ‘core’ language for getting things done.

I tend to use more of MVC framework strategy. Primary reason being: once i have setup the project, it takes less time in maintaining the “files”. That said, i can focus on working on getting things done faster while i have automation.

On the other hand, i have Setup 2 in place for my recent project, because of the project scenario.

However, i still prefer MVC frameworks to get the job done faster, more focus on coding.

Would agree with those comments :slight_smile:

Definitely MVC for me if I’m looking at building any application. The question I tend to ask nowadays is what is the best framework to do the job.

If it’s a big app then it would be ColdBox or Model-Glue. Smaller then I’d probably start to look into the latest one on the scene FW/1 - There is a pile of them out there though.

Talking about Javascript is a bit of red herring here as MVC regards this as part of the View along with your HTML, CSS etc. I know you’re aiming them as AJAX relationships to the framework but it’s really just a bolt on to the whole concept. You could put Flex, Web Services or framework plugins in the same category.

One thing you’ve not mentioned but worth saying is something Downtroden has lightly touched on - CFCs. If you’re looking at MVC then CFCs are your real driving force behind your app and that’s where your own management has to come into play as MVC doesn’t really help.

It’s worth spending some time with Design Patterns if you’re keen to get away from procedural and more into OO approaches. Things like Services, Factories, DAOs & Gateways, Iterators etc. REALLY help once you get your head around them and it’s something that isn’t CF specific. It’s worth looking at - and

for more information on the Patterns and how you can implement them in your Model.



Use of cfincludes to reduce redundent code

Look at custom tags instead of cfincludes. They still have their role in the CF world but can get out of control if you have a lot of them. Main reason being is you don’t know what’s the inputs / outputs of the include and makes it hard to manage.

Look to modularise your code with <cfimport /> libraries where you can as it’ll help you a lot more :wink: