Do you use MVC pattern?
Moderator: General Moderators
Do you use MVC pattern?
So I've been reading up on MVC lately and I think I do understand the concept. Right now I'm really interested if casual PHP programmers use it that much
. Also would be nice to hear your reasons on your decision and any comments you might have regarding MVC usage.
-
RobertPaul
- Forum Contributor
- Posts: 122
- Joined: Sun Sep 18, 2005 8:54 pm
- Location: OCNY
Just wanted to say, *excellent* phrasing of the question, and the poll answers. "Yes, as often as I can" shows a clear understanding that its not always possible.
Nice to see.
Thats what I chose. In my work life, I'd say my code is strongly MVC. In my hobby work, while its not currently MVC, I'm pushing hard to get it there. (The upcoming version of Blacknova Traders is FINALLY over the 50% templated mark! Woohoo!)
Of course, there are strict interpretations of MVC, and loose. I'm fairly strict, but every so often, you have to have some logic in the template.. as long as its not actually processing, I think thats solid.
Nice to see.
Thats what I chose. In my work life, I'd say my code is strongly MVC. In my hobby work, while its not currently MVC, I'm pushing hard to get it there. (The upcoming version of Blacknova Traders is FINALLY over the 50% templated mark! Woohoo!)
Of course, there are strict interpretations of MVC, and loose. I'm fairly strict, but every so often, you have to have some logic in the template.. as long as its not actually processing, I think thats solid.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
A bit like Roja, my current project (a game) is primarily an MVC structure. Its a custom design (there are pre-made frameworks all over the place these days) but it works quite well. Its one of those patterns you should read up in prior to use - even if you use a ready made framework it helps to understand all the principles involved rather than jump in the deep end without a clue.
As for casual use, I'd say yes. Most of my development is done as a hobby, and nearly all as open source. It largely depends on what you need. I made up a generic MVC scaffold for re-use, it works but its not a strict pure MVC implementation - nor is it a full fledged framework. I am using it in about 4 projects so far, so its seeing a lot of use and so far very few problems.
The documentation for a PHP MVC framework would be useful - PHP specific MVC documentation is far and few between.
As for casual use, I'd say yes. Most of my development is done as a hobby, and nearly all as open source. It largely depends on what you need. I made up a generic MVC scaffold for re-use, it works but its not a strict pure MVC implementation - nor is it a full fledged framework. I am using it in about 4 projects so far, so its seeing a lot of use and so far very few problems.
The documentation for a PHP MVC framework would be useful - PHP specific MVC documentation is far and few between.
MVC explanationonion2k wrote:I googled and found a definition .. and I have no idea if I use it or not. I doubt it. My understanding of compsci terminology is rubbish.
- trukfixer
- Forum Contributor
- Posts: 174
- Joined: Fri May 21, 2004 3:14 pm
- Location: Miami, Florida, USA
in a nutshell (a very basic nutshell) : separate display from logic (A.K.A. what I use Smarty Template system for)onion2k wrote:I googled and found a definition .. and I have no idea if I use it or not. I doubt it. My understanding of compsci terminology is rubbish.
you have code logic in script A , and you have the template (html, xml, whatever) in script B and teh controller that put sthe two together in Script C ...
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
- Buddha443556
- Forum Regular
- Posts: 873
- Joined: Fri Mar 19, 2004 1:51 pm
Voted sometimes. Do you use MVC pattern? Yes. I study it and it sometimes inspires me. That's about all I ask of any pattern.
MVC pattern talks a lot about separation. I think people tend to focus on this separation and lose sight of the purpose of MVC. The purpose of MVC is to make maintaining your code easier. Has any of the PHP projects that claim to implement MVC achieved this purpose? I don't know, I'm too busy maintaining my own code.
However, maintainability might be a better way to judge such projects than separation. Maintainability at least can probably be measured.
Achieving seperation of model and view is the easy part, being able to easily maintain that code ... that's tricky part.
MVC pattern talks a lot about separation. I think people tend to focus on this separation and lose sight of the purpose of MVC. The purpose of MVC is to make maintaining your code easier. Has any of the PHP projects that claim to implement MVC achieved this purpose? I don't know, I'm too busy maintaining my own code.
Achieving seperation of model and view is the easy part, being able to easily maintain that code ... that's tricky part.
I use MVC not just in PHP, but with development in any language. The degree of use depends on the application I am working on. I have yet to work on a program (even a one pager) where I am not able to use MVC structure to some degree. The end result, for me, is an application that is easier to work with and understand.
And MVC does not fit like a glove for any language as you have the database side of an application which has its own model and controller in the form of stored procs, triggers, views, etc.
On a side note, my personal view on this subject is that things like MVC structure and UML design is severly lacking in the PHP community. The focus is so much on making sure your code is bug free and efficient (unit testing), and so little time is spent on making sure what you build is what is actually needed. If you are building for yourself it does not matter, but if you build for someone else then pre development planning is (IMHO), by far the most important aspect of the project.
And MVC does not fit like a glove for any language as you have the database side of an application which has its own model and controller in the form of stored procs, triggers, views, etc.
On a side note, my personal view on this subject is that things like MVC structure and UML design is severly lacking in the PHP community. The focus is so much on making sure your code is bug free and efficient (unit testing), and so little time is spent on making sure what you build is what is actually needed. If you are building for yourself it does not matter, but if you build for someone else then pre development planning is (IMHO), by far the most important aspect of the project.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
There's a pretty good chance you do. To put it very simply... it's keeping what the users see away from the logic that goes into it... templating is a huge part of it.onion2k wrote:I googled and found a definition .. and I have no idea if I use it or not. I doubt it. My understanding of compsci terminology is rubbish.
I like your post and agree. I started using it before I knew what it was (same thing with the registry pattern) and have found it to be a huge benefit.Buddha443556 wrote:Voted sometimes. Do you use MVC pattern? Yes. I study it and it sometimes inspires me. That's about all I ask of any pattern.
MVC pattern talks a lot about separation. I think people tend to focus on this separation and lose sight of the purpose of MVC. The purpose of MVC is to make maintaining your code easier. Has any of the PHP projects that claim to implement MVC achieved this purpose? I don't know, I'm too busy maintaining my own code.However, maintainability might be a better way to judge such projects than separation. Maintainability at least can probably be measured.
Achieving seperation of model and view is the easy part, being able to easily maintain that code ... that's tricky part.
I might add that I think having easy to view or see (other then reading the comments) potential paths of logic really makes code easy to maintain. At this level, it doesn't even have to be OO to be easy to grok.