6 ms·
"The sleight-of-hand was the assumption—baked into the servlet spec—that each HTTP request would map to a single controller which would delegate to a single vie
by jerf 13y ago
"The sleight-of-hand was the assumption—baked into the servlet spec—that each HTTP request would map to a single controller which would delegate to a single view."
I've been struggling for a while to explain why I don't like MVC in web apps. Some of it is definitely just annoyance at how "MVC" has come to be simply a synonym for "good design" without any particular reference to any particular design, resulting in the term MVC being smeared over anything that has three classes that have a vaguely-plausible claim to fitting some interpretation of a "model" (this is the one most often got most correct), "view", or "controller" (both these latter just sort of get slung about with wild abandon). Despite how long it's been around, it is certainly a fad in every sense of the term, including large numbers of coattail riders and hangers on who don't really "get it".
But beyond that, regardless of what the "MVC" is, we've still got some sort of separation going on. But the separation is often pointless. The original MVC in the GUI arena was written for Ms, Vs, and Cs to be highly interconnected, not in the "coupling" sense but in the sense that there should be a significant number of many-to-many relationships between all the layers. But a lot of web "views" and "controllers" are used in only place, talking to only one other "thing", or perhaps the view talks to three "controllers" each of which is used nowhere else. The models are often reused, but more as just a data access layer.
If you don't have rich and free mixtures of all three pieces going on, you've split out your design on a useless dimension, and blown valuable design budget for a feature you're not going to use. And MVC is particularly designed for simultaneous usage of multiple things... one of the touchstones of needing the MVC model is when you have two simultaneous dynamic views on the same data, which multiple controllers may be simultaneously affecting. If you don't have that, seriously question your use of MVC.
Every once in a while, you may encounter a web app that really does deeply mix and match, in which case, go nuts. But it's going to be a special-purpose thing, not something used by everything. It's not always inappropriate... it's just that it's not anywhere near always appropriate, and it's appropriate rarely enough that it is, frankly, a stupid default for a web framework. Further, it's something that you can easily fold in only where needed; oh, do you have a statistics component where you really are using simultaneous views on the same underlying mutable data (perhaps a query)? Sure, use MVC for that. But as a default code structure? Be sure that mixing and matching Ms, Vs, and Cs at scale (not "I have this one class out of dozens that may sometimes need two views" but "this combination of 5 models, views, and controllers will be nearly arbitrarily mixed and matched") really is how your app's needs are going to change over time.
- mattmanser 13y agoI'll tell you one thing that I do not doubt. The splitting of the M, V & C is far better than bundling them in one page. I'd take a crap MVC design over the pre-MVC stuff I worked on any day of the week. The thing you don't seem to be saying is what you're doing instead? You're just waving hands at the moment and saying it's bad, but it used to be much worse.
- mattgreenrocks 13y agoIt's still the wrong approach to the problem. Desktop app UIs were never this painful. Even Swing's.
- endlessvoid94 13y agoThat's a really good point.
- king_magic 13y agoDesktop app UIs were never this painful? WPF, WinForms, WTL, MFC... all could be pretty darn painful when you got beyond the basic Hello World examples.
- AnimalMuppet 13y agoInterestingly, MFC was painful at least partly because instead of MVC, it wanted to drive you toward a Document/View architecture, where Document had both Model and View. This was painful exactly because of some of the problems that MVC was designed to fix.
- ollysb 13y agoYeah, enough with the hand waving. I can't say I've ever experienced any pain using MVC for web apps but I'm very happy to be enlightened. Let's see the side-by-side code examples (or if someone can can at least explain what they're doing instead I'll have a crack at it :) ).
- benjaminpv 13y ago