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.
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!
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.
Developers: We can use your help.
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.
Wait a second, there's programmers that aren't using only pure algorithms, refined from the finest electrons, bred from the keyboard controller outputs of Bjarne Stroustroup himself? Well damn, standards are just slipping everywhere. What next, thinking of the web as a platform? Client-side security? Linux on the desktop?
#fuckbeta #iamslashdot #dicemustdie
Since when did they let long winded douchebags with nothing to say have blogs?
Do you even lift?
These aren't the 'roids you're looking for.
I am intrigued by your Model View First post!11! software design pattern, and would like to subscribe to your newsletter.
I assume this pattern first involves thinking 'how is first ppost formed?' then going on to create a goatschema for the model, and finally rendering the first post by re-arranging the letters in some amusing way, e.g. fr1st p0st!!1
As I started reading, I discovered I don't care enough to read the whole thing.
But I thought the beginning was awesome: "You can disagree with me only if you are wrong."
To get a decent cross-language GUI engine, MVC has to be tossed or changed. The code that controls the event engine should not be app-developer-modifiable, for example. They can change the event priorities perhaps, but not the event engine. In essence, the "controller" needs to be hidden away, controlled by attributes only. Specific event handlers (functions or methods) are "called" by the event engine as needed.
It can all get so large that perhaps using a database engine of some sort starts to look worth-while. It's easier to study an event priority list or stack if one can query it rather than using set/get iterators. The grouping can also be query-controlled that way. One is not stuck picking grouping by task or grouping by screen or grouping by entity. The event code (or code reference) grouping could be by whatever you feel like for a specific maintenance task. GUI engines are outgrowing objects in my opinion. Objects are fine when you have hundreds, but not bajillions.
Table-ized A.I.
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.".
"I can break the MVC pattern when coding with Django, therefore it is not an MVC framework. Even if that weren't the case, I've got some bug up my ass about programs with more-or-less static output (webpages) being described as MVC."
There, I saved you a couple minutes and a whole lot of thinking, "And? What's your point?"
I'm assuming he pulled the uncited quote from the django book: http://www.djangobook.com/en/1.0/chapter05/
Here's another:
Taken together, these pieces loosely follow the Model-View-Controller (MVC) design pattern.
They don't seem to be too hung up on design pattern purity. Maybe it is different in IRC or the forums.
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.
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
No ads on this blog?
Really, what's the point of posting a long, pedantic, boring tirade about nothing and then submitting it to Slashdot if you can't 4) Profit?
Ugh. I only read about 2/3 of the way through. Did kdawson even bother to read halfway through? Even though I make a living using MVC frameworks, I just didn't really give a sh*t about what he was saying. Mod me redundant, but I feel better now having replied...
Can I please have those 10 minutes of my life back?
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.
I agree. This article was heavy on opinion and serves very little purpose. Who cares what this guy thinks about how certain, similar patterns are named?!
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.
I did some work under an absolute nutcase that insisted I use MVC while writing a wikimedia extension module. I don't get mvc implemented in php to begin with, but when I started getting the idea that he used the pattern for everything he did, I started getting the idea that I worked for a nutcase. Its a useful pattern for sure, but expecting a wrench to fix a problem that requires a hammer, or a screw driver, is a problem, imo.
Python: 'And then suddenly you have a language which says "we're all stuck with whatever the whiniest coder wants".'
This guy and his essay on the issue at hand is a breath of fresh air in a ongoing onslaught of web-developement misconceptions that increased tenfold ever since countless Java freaks joined the fray with the hype called Ruby on Rails.
I beg all people to read it and read it well. Please.
May I quote one part:
In the MVC pattern, the Model is the application object. It contains all the presentation-agnostic, data-centric logic, which is often labelled "the business logic".
Yes. Say it again. Halleluja!
We suffer more in our imagination than in reality. - Seneca
I'm glad I'm not the only one. When I first came across the web-based use of MVC I kept scratching my head and alternating between "WTF?" and "You keep using that word; I do not think it means what you think it does." After a while I realized that the web framework community had just latched onto MVC in a sort of cargo-cult fashion, without regard for it's prior meaning.
Not that it's the first time such a thing has happened. Think "structured" and "object oriented" or even "secure." For that matter, consider the fact that "Real" with the little swirly (as applied to cheese) is a trademark, not an adjective--the American Dairy Association could market tofu as "Real(tm) Cheese" if they wanted to.
The problem comes in when you start assuming that things that were true of the original use of the word are still true under the new use. Web-frameworks are MVC in exactly the sense that partially hydrogenated vegetable oil is cheese.
--MarkusQ
Considering that most developers using "object-oriented" languages don't seem to understand object-oriented programming, their failure to understand a particular pattern is not at all surprising. You can take a functional design, wrap it in an object, and say you're doing object-oriented programming, but that doesn't make it right.
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.
Comment removed based on user account deletion
If it walks like a duck, quacks like a duck, and runs on Windows, it must be an MVC application. --unattributed, possibly from Microsoftology, MCSE III
The Hacker's Guide To The Kernel: Don't panic()!
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.)
Model-View-Controller -- unheard of and not used ... ;-)
at least for most hobby or PHP programmers
This is the same rant that happens every time a good idea gets corrupted in IT by marketroids or half bright monkeys:
OOP, relational databases, software libre (which isn't the same as open source BTW, and I prefer the term "libre" since the word "free" is overloaded and hence misunderstood in the English language), distributed computing, WWW, XML or whatever.
One of the many reasons I have chosen a new career path.
putting the 'B' in LGBTQ+
The issue I see MVC addressing is the transition from Model-View-Controller to Model-View (or Document-View) to just plain View, or widget, the MS Windows default state of affairs.
The temptation is to place all of the functionality into one entity -- a widget, an ActiveX control. Model, GUI presentation logic, how it interacts with everything else, all this is packaged into a unitary entity. Great for lock-in to a vendor or OS or platform.
In my thinking, controllers serve a useful purpose to break free of vendor-GUI lock-in. The model, of course, contains the data and logic in a GUI-agnostic way. But the problem is that "model" may only constitute 10 percent of your program -- the bulk of code in a GUI app deals with GUI concerns of one kind or another.
The controller, on the other hand, contains GUI logic, but in a platform-agnostic way. It is the view and the view alone that has the lock-in to Windows or Java Swing or whatever the GUI-du-jour. Separating view and controller, I believe, is the way to get more of your application not tied into whatever GUI you are using.
what a whiner.
Yes, but there is (or at least was) more to it than that.
The model is/was supposed to house all of the details about how things interact, without regard to how you want to look at them (views) or mess with them (controllers).
Nowadays, models are more times than not just a sort of glorified persistence layer, describing the data in static terms and lacking the juicy details of how the data dances.
--MarkusQ
Can we have a glossary or something? I've been programming (C, Assembly, some C++) for 10+ years and I have no idea what the author is talking about or any of the commenters here. Patterns? Templates??
Here are some interesting notes from Trygve M. H. Reenskaug, who originated the term "Model/View/Controller" while at Xerox PARC in the 70's.
http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html
He seems to be a pretty remarkable character... still hacking at the age of 78, with a note on his new project:
I was at a rather fine presentation at a Java user conference once. It looked like a demonstration of Eclipse refactoring: everything was refactored into patterns. The guy new all the right key bindings and everything moved blindingly fast. Within half an hour fields were moved/introduced, factory methods and classes created, variables renamed: it was rather fun and impressive to look at.
Then - in the second half - he explained in depth that he just made a complete mess of a perfectly fine and simple *working* application by introducing all these patterns. Funny and a lesson people won't forget easily.
I don't really see why discussing MVC is as all that and a bag of chips as the author contends. I commonly use the concept of MVC with respect to Django and when I do I always reference this book:
Using the definitions as described in this book Django easily fits in the MVC design pattern.
People I work with "get it" and I've not encountered and confusion alluded too by the author when using the term as defined by the aforementioned book.
Language is always evolving and that is how non-technical words end up with multiple variations in the common language dictionary. I see no reason why technological terms should be excluded from this "language pattern". There is no notion that technogical terms have to stick to some "original definition". The book above provides a working definition that is common and clear.
There is a widespread presumption that all good GUIs are MVC based. So, to get approval for a design you have to dress it up in MVC terminology, whether that makes any sense or not. After twenty years of this, the terms no longer even mean anything, since so many wildly differing things have been labeled MVC. Time has transformed an excellent pattern of limited applicability into a useless time waster that must be applied to everything.
http://xkcd.com/756//
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?
I argued much the same thing in much less space 2 years ago. :-) Most "MVC" web frameworks are anything but, and it is disingenous to claim that they are. It's a marketing gimmick for people that don't actually know what they're talking about.
--GrouchoMarx
Card-carrying member of the EFF, FSF, and ACLU. Are you?
After week of use, I mentally mapped their terms Model, View, Controller to Stick, Carrot, Snowman, and it doesn't confuse me since.
I find this is more of a problem in web development than in classic application development. The problem stems from the fact that anyone can do HTML and many web "developers" have moved from that to languages like PHP that don't teach or enforce good use of OOP, type safety and other important concepts. It's not bad that PHP doesn't do that in itself, because it's still a good language for knowledgable, sensible programmers but that's not a large part of it's userbase unfortunately.
The problem is demonstrated strongly with the likes of HTML5, this goes against everything good that has been done in XHTML to push separation of concerns because doing so is important for an accessible, consistent, well built web. I don't agree entirely with some of the design decision of the newer releases of XHTML- phasing out tables seems to be one of the worst ideas but it's still a whole lot better than mixing up content, presentation and so on into one big single mess.
The two sides are basically this, if we allow lazier development we end up with a much less accessible, much less portable web but we get more content because anyone can publish even if what they publish is badly developed. The alternative is we push for much stricter web development that requires a lot more skill and discipline to do properly and results in a much more portable, accessible web but has the downside of less people publishing because some wont want to make the effort.
It's a hard choice for sure, personally I'm on the side of forcing people to do it properly if they want to do it at all, but I do understand that may isolate people who do benefit the web with useful (albeit poorly implemented) sites and content.
People saying that the view should have zero logic in it simply don't get it. The view should have no business logic, but it doesn't mean the view cannot have logic at all.
And it's not "one or the other". Take data validation for example: it is perfectly valid (and very often recommended, for bandwith saving purpose and responsivness purposes, etc.) to do some data validation on the client side in a Web browser. Does this means that if you do that you don't do validation on the server side anymore? Of course not...
Regarding Java as being "nonsense" for the Web: the biggest websites of this planet (GMail, FedEx, eBay) are backed by Java webservers. And websites that don't scale, once too succesful, are rewritten in Java...
...that MVS is _right_ and leaving that pattern is _wrong_.
Which is not always correct.
My Journal
I think MVC was a fairly valid pattern for web development prior to the development of AJAX technologies and the advancement of JavaScript as a language.
However, with these developments the pattern applied by rote makes things seem simpler than they are.
From a perspective of working in web dev I tend to see things more as follows:
Model: The database and its DDL statements
Meta-Model: Server-side represenation of the databases stucture and data. The bridge between the actual Model and the Controller
Controller: Sever-side central code that fits into a grey area.
Meta-Model: Server-side reprsentation of the View.
View: What ends up in the browser. A combination of HTML and JS.
From my perspective, The Controller interacts with the Model via the Meta-Model to produce the View via the Meta-View.
The View, for its part, is capable of interacting with the Controller in turn thanks to AJAX and such interactions should be managed by the Meta-View.
This is overall a more complex scheme than basic MVC but is also, I feel, a little more representative of the actuality of things.
If its JS, rather than just HTML, it could certainly poll a message queue, which (given suitable tolerance for latency) would allow it to accept and respond to callbacks, albeit asynchronously rather than synchronously.