Slashdot Mirror


Model-View-Controller — Misunderstood and Misused

paradox1x writes "Malcolm Tredinnick shares a terrific rant against the misunderstanding and misuse of the Model-View-Controller design pattern. In particular he takes issue with the notion that Django should be considered an MVC framework. He says that 'It's as valid as saying it's a "circus support mechanism," since the statement is both true, in some contexts, and false in others (you can definitely use Django-based code to help run your circus; stop looking so skeptical).' I'm not sure I agree with the entire piece, but it is a very good read." We recently discussed another look at the bending and stretching of MVC patterns in the world of Web development.

20 of 221 comments (clear)

  1. Pedantry by Anonymous Coward · · Score: 5, Insightful

    So let me get this straight: you're upset because some developers are misusing a term and giving their product more credit than it should have?

    Well, that's never happened before!

  2. Web Frameworks by truthsearch · · Score: 4, Insightful

    The custom web framework my company uses helps program with the MVC pattern, but doesn't enforce it. Some developers are very consistent with separating the model, templating, and control structure. Some developers (not always the less experienced ones) often intermingle functionality and don't realize they're no longer within the MVC design. So our framework is nice that it's flexible, but it also will let you hang yourself. Most other frameworks, at least for PHP and Python, seem to be the same way.

    1. Re:Web Frameworks by Anonymous Coward · · Score: 1, Insightful

      I don't use Ruby or Rails, but I do like the idea of punishing deviant developers! Seriously, if there is a conceptual model around which a framework is based, going out on your own is punishing the other poor suck who inherits your code. Take the time to grok the concept and write to it. It's a good principle to make writing good code easy and writing poor code difficult.

  3. Author is Pedantic by iluvcapra · · Score: 5, Insightful

    And does quite a bit of complaining about Django without completely demonstrating his point. I'm still foggy about his complete idea of what he believes the original interpretation of a "Controller" is, which is really the heart of the matter and where most people seem to disagree. His "model" of what MVC is is not explicated in his view, as represented by his blog post.

    MVC is a pattern, not a set of rules, a coding style, house style, development framework, or development process. If you have three modules, one doing presentation, one doing state, and one mediating, you're doing MVC. What specific functions go where (is sorting on the model? is validation of this field in the view?) is specific to the problem domain.

    IMHO

    --
    Don't blame me, I voted for Baltar.
    1. Re:Author is Pedantic by Foofoobar · · Score: 1, Insightful

      The view should do ZERO processing. That should settle it. Some templates allow for a minimal amount of if/else statements and some developers are just sloppy and stick in processing anyway when it should be moved to the controller.

      The model should handle all data, the controller should handle processing and the container should handle higher level functioning for gathering the model, the view and the container.

      See PHPulse as a very simple example.

      --
      This is my sig. There are many like it but this one is mine.
    2. Re:Author is Pedantic by LaskoVortex · · Score: 3, Insightful

      I'm still foggy about his complete idea of what he believes the original interpretation of a "Controller"

      It's always good to define one's terms before one begins to write about them. If you ask 10 different experienced developers what MVC is, you'll get 10 different answers. The problem with this article is that we never get what the author's interpretation of what MVC really is.

      But no matter what one's definition of MVC, its like OOP. With OOP, it has been said that any substantially complex system is actually going to require some sort of implementation of OOP, even if its hopelessly half-assed. The same can be said for MVC.

      Of course I just committed the same omission as TFA in that I haven't defined exactly what I mean by the terms I use.

      --
      Just callin' it like I see it.
    3. Re:Author is Pedantic by plover · · Score: 2, Insightful

      How do you reconcile view caching with this idea? I'm not arguing with you, mind you, but I'm wondering that if there's a cache involved does that immediately negate calling the pattern MVC? Another violation of this is AJAX. It has logic as client-side as you can get.

      I think what the TF author might be thinking is that MVC means exactly this pattern applied at this level, and not scaling the pattern up to web server / app server / database server. Or if that's it, then we shouldn't call it MVC but something else like "P-BL-DA" for "Presentation / Business Logic / Data Access". (Or maybe DA-P-BL, in honor of the original screwing up of the order of the layers in the name.)

      --
      John
    4. Re:Author is Pedantic by KDR_11k · · Score: 3, Insightful

      I think the idea is that the view is interchangeable and isn't expected to do anything in order to allow the system to function but it can of course have extra functionality that is not necessary but increases the userfriendliness. The view can validate the user inputs to spare the user some grief but the controller should never expect the view to behave in any way.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    5. Re:Author is Pedantic by KDR_11k · · Score: 2, Insightful

      I'd be hard pressed to envision a scenario where field validation is logically a -view- function.

      High latency or intermittent connection scenarios where you can't check back with the controller all the time and it's better to avoid unnecessary calls if you can tell the user that the input is invalid anyway? Sure, the controller would of course still do validation but that doesn't mean the view can't tell you what's wrong without needing to connect to the controller.

      --
      Justice is the sheep getting arrested while an impartial judge declares the vote void.
    6. Re:Author is Pedantic by mini+me · · Score: 2, Insightful

      Sounds exactly like how Rails does it, and has been doing since long before PHPulse was ever released.

    7. Re:Author is Pedantic by lgw · · Score: 3, Insightful

      When I firt read Design Patterns 15-ish year sago, I was hoping for a book of insightful best practices, but instead found a bunch of ideas that were obvious to anyone skilled in the art, being given arbitrary names and then heavily obfuscated with UML. The majority of these "paterns" were things that were trivial to implement in (or just built into) other languages, but hard to do in C++. Somehow people thought this was ome major revelation. I still don't get that.

      And IMO it did more harm than good, merely because people saw "singleton pattern" and reverted to heavy use of global storage claiming "it has to be OK, it's a design pattern". Sadly, that's the one that fresh college hires do seem to know.

      Of course, I do work with device drivers and other "systems" code, not CRUD code, so maybe I'me just not in the right field to "get" these.

      --
      Socialism: a lie told by totalitarians and believed by fools.
  4. Django by styrotech · · Score: 5, Insightful

    I was under the impression that the Django team don't consider it to be MVC themselves, but they've just given up the losing battle of explaining the difference to the masses who think that MVC is the only good way you can arrange 3 different tiers of an application. So they've shrugged their shoulders and effectively said "Fine. If you want Django to be MVC, it is MVC. Now drop it and let us get back to developing it.".

  5. More Buzzwords From Lazy Programmers by Anonymous Coward · · Score: 1, Insightful

    Whenever I hear people yammering on about development model framework concept engine controller view model buzzword bullshit bingo, I know that they have a difficult time of looking at a problem, understanding it, designing a program, and then keeping their nose to the grindstone until it's correctly implemented.

    Programming is very simple, and it's hard. Decades of delusional wishful thinking by people trying to make it easy and complex won't change that.

    And stay off my lawn.

  6. Wrong. by Qbertino · · Score: 3, Insightful

    Author is Pedantic

    No he isn't. He critisizes the incorrect use and application of the term MVC and the misconception and the pointless enforcement of a wrong concept of MVC in places where it is often more than pointless to do so. Like in most modern web application scenarious.

    And does quite a bit of complaining about Django without completely demonstrating his point.

    No he doesn't. He uses Django as an example for all current hip Web FWs out there to emphasise the issue above. And he clearly states that before he even goes into Djangos documentation and concept of MVC.

    --
    We suffer more in our imagination than in reality. - Seneca
  7. Re:huh? by daveime · · Score: 2, Insightful

    About 27 nanoseconds after the first blogging software was created.

  8. Author is Pragmatic by Anonymous Coward · · Score: 1, Insightful

    I disagree on the author being pedantic. I believe the author is calling people who hold up "MVC!" as the one true programming model are the ones being pedantic.

    Django (and similar frameworks like Rails) are NOT pure MVC. We can in some ways map the Django concepts to MVC concepts that they're similar to, but they're not the same.

    I believe the author raises the question of whether "Django makes it easy, so do it!" is right. MVC purists would want to strongly separate things that it's easy and simple to do together in Django, simply for sake of a model that Django doesn't directly support. The author appears to contend that doing that is fooling yourself.

    Use Django because you want to use Django, and it makes it easy to do what you want easily. Not out of some misguided view of MVC purity. If it's easy to use Django and Python to do something that you need to do, but it breaks some purity from MVC, don't worry about it.

  9. MVC is good by bytesex · · Score: 3, Insightful

    MVC is good. When you understand it at its simplest. But it doesn't need a 'framework', which is where the confusion creeps in. Java is on the one hand so popular, yet so hopelessly constrained in its possibilities and libraries, that apparently this confusion seems to have become 'unrecognisable' as it were: people automatically postfix 'framework' behind 'MVC' because it's so difficult to build web-applications in java without one (well it's not, but they don't usually know that either).

    A framework is a meta-language in essence, it 'sits on top' of your project. Libraries OTOH are (usually) written in your own language and 'hang below' your project (i.e. you use them, instead of it using you). Both can provide MVC, but both can provide many other things as well.

    I prefer libraries me. I like to know where a request comes in, and be there when it happens. That said, libraries that model my data storage in nice structures and provide templating for output are yummy. But that's all - I feel the programming language should be *my* bitch, not the other way around. So yeah, I've had to write my own template rendering code since the existing ones all had unnecessary limitations rooted in the theory that the template shouldn't contain any code (so how are we supposed to go about iterations, theorists ?) or any complex variables (yet your data modelling library provides for those, thanks a lot !). Took all of a monday afternoon that.

    --
    Religion is what happens when nature strikes and groupthink goes wrong.
  10. Re:Apply MVC (or any pattern) where it can be used by CodeBuster · · Score: 2, Insightful

    From Head First Design Patterns:

    The beginner sees patterns everywhere. This is good. The beginner gets lots of experience with and practice using patterns. The beginner also thinks, "The more patterns I use, the better the design." The beginner will learn that this is not so, that all designs should be as simple as possible. Complexity and patterns should only be used where they are needed for practical extensibility.

    As learning progresses, the intermediate mind starts to see where patterns are needed and where they aren't. The intermediate mind still tries to fit too many square patterns into round holes, but also begins to see that patterns can be adapted to fit situations where the canonical pattern doesn't fit.

    The Zen mind is able to see patterns where they fit naturally. The Zen mind is not obsessed with using patterns; rather, it looks for simple solutions that best solve the problem. The Zen mind thinks in terms of the object principles and their trade-offs. When a need for a pattern naturally arises, the Zen mind applies it, knowing well that it may require adaptation. The Zen mind also sees relationships to similar patterns and understands the subtleties of differences in the intent of related patterns. The Zen mind is also a beginner mind, it doesn't let all of that pattern knowledge overly influence design decisions.

  11. Bulshytt by 0xdeadbeef · · Score: 1, Insightful

    In web applications the generated HTML is the view. The template code and javascript are the controller. The model is anything and everything providing input to the template.

    Just because something is painful or stupid doesn't make it any less MVC.

    (What would break his precious pattern definition is putting data-mutating logic in the template, like every php application ever written. Which I guess is the only real value of MVC - it's a simple rule of thumb to prevent noobs from hurting themselves.)

  12. Have you every noticed? by codepunk · · Score: 2, Insightful

    Have you ever noticed that guys that write subject matter such as this are the
    ones that could not code themselves out of a paper bag?

    mvc bla bla bla views bla bla bla models bla bla bla

    --


    Got Code?