32 ms·
I'm certainly not the first person to notice this, but the problem with MVC as given is that you end up stuffing too much code into your controllers, because yo
by icebraining 13y ago
I'm certainly not the first person to notice this, but the problem with MVC as given is that you end up stuffing too much code into your controllers, because you don't know where else to put it.
No, that's just with the bastardized version of MVC popularized by Rails et all, which treat the views as little more than templates.
In the original MVC papers from Smalltalk, the views did actually send messages updating the model:
A view is attached to its model (or model part) and gets the data
necessary for the presentation from the model by asking questions.
It may also update the model by sending appropriate messages.
All these questions and messages have to be in the terminology
of the model, the view will therefore have to know the semantics
of the attributes of the model it represents.
http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf
- bowlofpetunias 13y agoMost criticism of MVC and frameworks can be summarized as: "I don't understand MVC, this framework I'm using doesn't supply me with a one-size-fits-all architecture for my business logic and I'm incapable of designing my own. So I'll just stuff my spaghetti style code somewhere, and bitch about MVC and/or the framework being insufficient/dead/shit." It's the ultimate expression of a bad craftsman blaming his tools, and it's endemic in web development.
- hvidgaard 13y agoI've lost count of how many times I've had to argue that the View binds (loosely put, for View <-> Model interaction) directly to the Model. The Controller only enters the chain if the operation is more complex, i.e. it is a composite operation. That said - the Controller is the only place that is left if the code isn't interface or datastorage specific, so naturally it's the first place to get bloated. But that's fine, you just have to take care of that when you can, by abstracting common functionality and/or move it out in a library.
- gizzlon 13y ago"this framework I'm using doesn't supply me with a one-size-fits-all architecture for my business logic and I'm incapable of designing my own" Funny, because too me that seems like the whole point of MVC: To have a one-size-fits-all "architecture" to shoe-horn your business logic into. But then again I never really understood the point of MVC. It seems like a somewhat nice fit for GUI applications, but that doesn't mean you should use it for everything. The real takeaway is to decouple and abstract to the point that makes sense. Not too much and not too little.
- popee 13y ago> it's endemic in web development Important word here: 'web'. If you move that word all ror puritanism falls apart. For example imagine multi-protocol MVC. In that sense javascript is really part of view and it can 'pass messages' to model using ajax.
- hnriot 13y agoyeah, that's really relevant. smalltalk, 1979!
- mjburgess 13y agoSaid the inventor of rails... (...?)
- Nekorosu 13y agoYou are as funny as ignorant.
- bdcravens 13y agoDHH called a Smalltalk book one of the best programming books ever: http://37signals.com/svn/posts/3375-the-five-programming-books-that-meant-most-to-me http://37signals.com/svn/posts/3375-the-five-programming-boo... So I'll step out on a limb and say that it strongly influence(d/s) the design of Rails
- rubiquity 13y agoRails didn't bastardize MVC, users of Rails bastardized MVC. Over the years we've seen the progressions of fat controllers to skinny controllers and fat models. Now, we're seeing the progression of using models only for responsibilities related to persisting the object. This leads to extracting additional domain logic into Presenters, Value, Service objects, etc. Avdi Grimm has a great book about this called Objects on Rails[1] and Bryan Helmkamp from Code Climate has a good introductory blog post on it as well[2]. Rails implementation of MVC is perfectly fine. It's when people lean on MVC for everything without applying "classic" Object-Oriented design. That's when things become a mess. 1 - http://objectsonrails.com/ http://objectsonrails.com/ 2 - http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/ http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decomp...
- pothibo 13y agoThe decomposition of ActiveRecord Object is not bad. I don't like class like UserAuthentication and AbandonedTrialQuery. I would rather have something like. #app/models/user/query.rb class User module Scopes #my scopes. end end
- rubiquity 13y agoEveryone has their own preference for implementing object oriented design which will help push things forward. The important part is that people are thinking about object oriented design more than ever before.
- pyrocat 13y agoAs an aside on terminology, why do we use the terms "skinny" and "fat"? Shouldn't it be "short" and "tall" since code is represented vertically?
- roryokane 13y agoI imagine the words as analogies to people and their ease of movement. Fat (“bloated”) components are hard to work with and develop, in the same way a fat person has trouble running from point to point. On the other hand, skinny components are easy to work with because there is little to comprehend, the same way that skinny (“lean”) people will run more quickly and easily.
- Chris_Newton 13y agoInteresting link. Do you know the original context? I’d be the first to agree that a lot of back-end web frameworks have wildly distorted the original idea of MVC, and in many cases completely missed the point of why it was useful. However this is the first time I’ve seen anything from the original Smalltalk days that presented the relationships like this, with views affecting models and a controller implicitly being related to multiple views.
- rubiquity 13y agoThe original MVC was invented in the context of a fat client which were desktop-esque applications back in the day. In the context of the Web and HTTP (which is a stateless protocol) MVC had to be adapted to fit this context which is what Rails and many other frameworks have done. Now with browsers and JavaScript performance being better than ever, preserving state seems possible so a more "original" MVC implementation can (possibly, everyone is still debating this these days) work on the client side. Rails and the other MVC frameworks don't just focus on the client-side, however. They are also deeply involved with the database and everything in between so a pure implementation of MVC is out of their reach. On the Web in the next 5-10 years maybe we will see more frameworks separating the concerns of the Web server/database and the client-side. Once we break those apart you can have a Smalltalk style MVC implementation on the client-side and organize your "back-end" code to your hearts desire or use a back-end specifc framework to guide you there.
- Chris_Newton 13y agoNow with browsers and JavaScript performance being better than ever, preserving state seems possible so a more "original" MVC implementation can (possibly, everyone is still debating this these days) work on the client side. There is little need to debate that point. Doing MVC-style architecture on the browser side works just fine. One of my long-term projects is a relatively large web application that uses something very close to the original MVC idea, with a central model that holds all the state and then a few dozen view-controller pairs that handle all the ways of interacting with it. This architecture has served me well for several years now, and the design has proven to be very easy to maintain and adapt to changing requirements. (In practice I add a fourth type of component in the web context, a “store” that is responsible for communicating with the server, and I define a small number of additional relationships to go with it because it doesn’t fit into any of the other three categories. Even then, the store acts somewhat like a view-controller pair for most purposes, and the cases where it doesn’t are mostly things I might do differently with the wisdom of hindsight.) On the Web in the next 5-10 years maybe we will see more frameworks separating the concerns of the Web server/database and the client-side. I’m not sure why we need any distinction between them. Ultimately, we’re just writing a distributed application, which happens to run using something like HTTP as a communications protocol in this case. All the usual concepts about maintaining state and actions that have side effects apply, and all the usual arguments about separating such concerns apply. What makes you think we can’t use these ideas already today?
- ericgoldberg 13y agoActually, a good code smell / architecture smell in a Rails app is if any given controller method is over 10-15 lines (And even that is on the large side IMHO). For example, I believe Code Climate specifically penalizes your score for long methods in controllers. I write plenty of Rails apps that have thin controllers and fat models. Class methods / static methods on models can help encapsulate business logic in any language's MVC frameworks, as well as liberal use of the Tell Don't Ask pattern.
- alttab 13y agoNice, clean, and crisp.
- steveklabnik 13y ago> No, that's just with the bastardized version of MVC popularized by Rails et all, which treat the views as little more than templates. While Rails did use this and make it popular, it's older than that: http://en.wikipedia.org/wiki/Model_2 http://en.wikipedia.org/wiki/Model_2
- sklivvz1971 13y agoLet's not confuse activerecord with MVC though. Rails suffers beacuse of AR not because of MVC.
- e12e 13y agoA nice way of putting it. Somewhere along the line of web/http systems views became templates -- while an MVC "view" really is (some) logic+rendering -- not "just" rendering. I'm not sure if rails is the first offender here -- php (and asp, jsp etc) makes it so easy to drop a ton of complexity on your lower extremities that it becomes necessary to "ward off" the part that actually does templating from the rest of your code -- which, if it's all old school php -- isn't terribly easy to do -- or at least isn't trivial to make "obvious" in your code. If you fail to maintain a part of your code as template-php, and mix it up with your logic, your nicely structured application quickly becomes a mess (this is what old php codebases I've looked at looks like -- and has left me a a little resentful against the entire language. Probably more than php deserves).
- camus 13y agophp is not a framework. How many people use bare ruby , bare python or bare java to code webpages ? ( and by the way JSP can be a mess too , so it's not about the language,it's about the brain behind the desk ). Rails , Django and others give devs MVC for free , not PHP, not Ruby , not Python.
- dalore 13y agoIsn't that a presentation model? Where the view gets it's own model so you can swap out different UI implementations.
- asdasf 13y agoI am amazed at how one web framework managed to completely redefine a long standing pattern in such a short time. MVC is quite old, and well established, and was even used in web development well before rails came along. But now suddenly 99% of people think MVC means a rails style mess.