Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Hey... its XMAS Eve and something is bugging me... yes, I have work on my mind even when I am on holiday. The vast amount of frameworks available for PHP now use MVC. Even ASP.net has its own MVC module.

I can see the attraction of MVC, I really can and I use it frequently. The only downside that I can see is that you have to fire up the whole system to execute a page request. Depending on your task this can be a little wasteful.

So the question. In a professional environment is this the only way to use PHP nowadays or are their other design methods which have alternative benefits?

share|improve this question
1  
What does "fire up the whole system" mean, and how is this required by MVC? MVC is just a design pattern. If you're using PHP, you're already using server-side code, and you can't really have an interactive website without client-side code, so I fail to see what part of the "system" is not being used. Or why that part MUST be used when you use MVC. –  Matthew Read Dec 25 '10 at 5:13

5 Answers 5

no. What pattern you use always depends on the task your programm/script has to perorm. Just yesterday I had to solve this:

  • show the mtime of two files
  • show number of temp files in a folder
  • allow deleting all temp files with one click
  • web interface

I know one could argue that a nice reusable MVC sollution would be cleaner, but I choose a 20 lines of sequential code. Why? It is fast. It is small. And every minute I spend on this is a minute I can not use on my main project.

(let the hate begin!)

share|improve this answer
    
Yay! Infact I would like to add up that most new programmers are generally picking up MVC because the world does that :| , even when they just want to print a few lines! –  Abhinav Gauniyal Aug 22 at 2:21

The thing to think about is not whether using an MVC framework is justified, it's maintainability. Sure, it may be small now, but will it always be?

share|improve this answer
    
+1 for size helping maintainability. ALso another thing to remember is the execution time limit which is why why you usually want to keep things as small as possible when you can. –  wildpeaks Dec 24 '10 at 21:10
    
I am not really talking about whether you need to use an MVC framework. It is more about the MVC pattern in general when designing an application. –  JasonS Dec 24 '10 at 21:13

Well there are a lot of other approaches.

MVC is just popular because it suits most situations (or better said can be used in most situations) and has established itself as a de-facto standard.

What can be said is that every programming/design pattern - or more specific architectural - depends on some classification.

Those are often (of course they can be devided further):

  • User Interface (pretty images, forms etc)

  • Application (your application logic and stuff that needs to be secured from the client - ak lot of that can often be done in the user inteface, eg. by javascript)

  • Database - self explaining

  • Infrastructure (very basic stuff like hard disk, server systems, network etc.)

Of course there is always the naive, procedural straight-forward approach but also a lot fo other patterns that can link and structure the access and controlling to these basic layers.

Mvc is one of them. But here are some example of others:

http://en.wikipedia.org/wiki/Model_View_ViewModel

http://en.wikipedia.org/wiki/Model_View_Presenter

http://stackoverflow.com/questions/140098/is-mvc-ars-preferable-to-classic-mvc-to-prevent-overloading

And here a lot more:

http://en.wikipedia.org/wiki/Architectural_pattern_(computer_science)

share|improve this answer
    
I hope you meant native and not naive procedural straight forward approach :P –  andre Dec 25 '10 at 13:06

MVC is usually the most natural way of separating concerns in medium to large web applications. Nobody says you have to do it that way. If your domain suggests another way of separating the application into manageable pieces then you should do it that way. Chances are high though that you'll settle on a variation of the MVC pattern if you separate the application logic properly.

share|improve this answer

Everything depends on the task at hand. There are no exceptions for this proposition for any topic. Be it MVC, Web Design, API programming, or even cooking. That's logic.

In regard to programming, for a particular task MVC may be overkill, or unsuitable. A 100 line script may be faster or more maintainable. Totally depends on task. You dont need to load up a beautifully structured, templated MVC app for an API that is only going to get a piece of data from a db table and serve it to a particular request.

MVC is better in cases that you may reuse the code, or would need to expand it in future, or need to maintain it for any particular reason.

And a note in regard to sequential vs oop - everything happens sequentially in a program. There cannot be two states of the same variable under same conditions. A shopping cart object itself cannot have two values for the same customer with same products with same options with same shipping locations and tax details. Or, you cannot create a shopping cart object and write the products in it before customer actually adds any products to the cart. It would be surreal. Something that requires particular conditions to happen cannot happen without those particular conditions being met, in programming. (And no - just initializing a potential predictive object class for a potential data object is not relevant).

So therefore think practical - do whatever the task in hand and its potential near, mid, and long term requirements necessitate.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.