Live data from Hacker News

MVC is dead, it's time to MOVE on

cirw.in

221–230 of 233 posts

Re: MVC is dead, it's time to MOVE on

#221
post #219
post #133

Earlier quoted context omitted.

I'm currently building a single page app using this MVC-MVC approach. I use Angularjs in the browser, now.js for the interface, and, at the moment, custom code on the server that follows the MVC pattern. The server is lightweight: its role is to * manage authentication and authorizations, * ensure data integrity and * push data on update according to user permissions. That's it. http://angularjs.org/ http://nowjs.com…

I am doing a simialr thing. Except ASP.NET MVC 4 Web API on the server and Angular.js on the client. It feels very natural and simple to me. What I find odd is Angular.js works very similar to Silverlight, and my whole setup has similarities to Silverlight with RIA services. Yet SL+RIA never felt natural at all and was very difficult. I've not narrowed down where the difference lies.

Angular is very impressive. There are lots of small things that make it nice to use. Among them:

The lexical/nested scoping in the templates is just perfect. I've reviewed the documentation of all competing frameworks, and I couldn't figure how to do it in any of them. Since it was a primary requirement for my app, I went for Angular.

The service-based architecture, and the automatic service injection in controllers, based on parameter names are pretty nice too, as is the fact that you can pass arbitrary parameters to filters.

In a calendar widget that displays a month, I pad the `month` array with days of the surrounding months in order to get complete weeks. I wanted to have these days styled differently. `dayName` and `idem` are custom filters.

    
        
            {{day.date}}
            Events go here.
        
    
In CSS:

    .this-month-false{opacity: 0.7;}
    .sunday{clear:both}
    .day{float:left;width=...;height=...;}
Bam: calendar!

Re: MVC is dead, it's time to MOVE on

#222
post #72

If your controller has too much logic you should really consider putting more of it in your model and view. Maybe I don't understand MVC, and you all can tell me How Wrong I Am, but here's how I understand MVC at present: Your Model is a public API, a Service Gateway -- and it should do a couple of things in principle. The first is that it should be able to manage a list of subscribed view/controllers, and push updat…

"If your controller has too much logic you should really consider putting more of it in your model and view."

The problem with MVC is that it makes people think that there are only supposed to be three things, and if something they require doesn't fit into thing 1, and doesn't fit into thing 2, then it must go into thing 3, instead of inventing a new thing 4 for it. Most real-world software is complicated enough that it requires more than three pigeon holes. Cargo-cult MVC programmers who can't think outside of three boxes are why the Controller usually gets gang[4]-banged into a kitchen sink of everything that didn't fit into the model or the view, because the words "Model" and "View" have easily understood meanings, but "Controller" could mean anything, so it gets some of everything.

Re: MVC is dead, it's time to MOVE on

#223
post #220
post #59

Earlier quoted context omitted.

I suspect this is because most people do not actually understand what MVC is and how it applies to server-client relationships; in fact, the wikipedia article on MVC is slightly off on the subject, assuming one accepts the original Xerox description as a source. Try not to wrap the entire complicated application into one big MVC umbrella because that will just confuse. There are actually multiple processes involved,…

This sounds interesting. What Xerox document are you referring to and what is the most relevant part?

I found a blog post that gives a rundown on the evolution of MVC (https://billkrat.wordpress.com/2010/12/23/hello-world/) and links something similar to the document I had originally read (http://heim.ifi.uio.no/~trygver/1979/mvc-2/1979-12-MVC.pdf). I think I had originally found something that was more of a prototype of this document, but the wording appears to be the same and more succinct. The blog post also links to an earlier version of the MVC model that included a fourth part, a "Thing".

One thing I found interesting in the blog article was the notion of "smart controls", but I can rationalize that away as another MVC module; after all, the Windows OS itself is handling all the interesting behavior, and the GUI app is borrowing the behavior. Depending on the toolkit that interfaces with the "smart controls", we get access to events (mousedown, keypress, etc) that can serve as input to one of our application's controllers.

Re: MVC is dead, it's time to MOVE on

#224

Earlier quoted context omitted.

> in fact, the wikipedia article on MVC is slightly off on the subject, assuming one accepts the original Xerox description as a source. People complaining about factual inaccuracies on Wikipedia annoy me. It's Wikipedia. The entire point and purpose of it is to fix what you know is wrong. For once, I'd like to see, "I just touched up the Wikipedia article on this subject to explain it a bit more accurately."

>"I just touched up the Wikipedia article on this subject to explain it a bit more accurately." "But then all my changes were reverted by an overprotective editor; I brought the issues up on the talk page, but my comments were brusquely dismissed."

Did that actually happen to you when you made that change or are you just assuming it would?

(In my experience most Wikipedia edits are gratefully received, assuming you provide references for your claims. Kind of like HN, really)

Re: MVC is dead, it's time to MOVE on

#225

Earlier quoted context omitted.

Your changes would still be in the edit log, and someone more savvy in Wikipedia politics would have the opportunity to get your changes cemented. Said person might be another HN reader who is less knowledgeable about the subject matter. If you don't make any changes, he has nothing to work with except some random whining. (And yes, that's how it works in the real world, too.)

Are you volunteering to help push through wahnfrieden's REST changes, then?

His comment does not imply they did not go through.

Re: MVC is dead, it's time to MOVE on

#226
post #214

Earlier quoted context omitted.

I dunno about the last part. I think any logic inherently tied to the data should be in the model. The controller shouldn't have to worry about internals of the model any more than necessary. Here's an example. Suppose I create an i18n framework for handling numbers. I certainly am going to include in it a function for converting the number into the current user's localized format, and another one for converting the…

Converting the display format of data when requested by a view is exactly what a model is supposed to do. However, instructing a contained object to take some action at the user's request that is unrelated to display or management of contained objects is neither the responsibility of the view or the model, but specifically the task of the controller.

Ok, so let's go further.

I want an email to be sent to me when the quantity on hand of a part gets below the re-order point.

So now, I build a program that listens for notifications, and when it gets one, loads the data, erases the queue, and sends me an email.

I build this so the app itself doesn't know this is required or is going on. Database triggers, queue tables listening scripts, and templates all are triggered when the db write takes place.

Now, what we have here are arguably two MVC environments where the model behavior of one triggers a model change in another, which triggers a controller to run, calls some other model stuff, creates an email (via a view) and sends it.

But this is the sort of action you are talking about, right? You think this violates separation of concerns?

Re: MVC is dead, it's time to MOVE on

#227
post #23

This sure looks like MVC, but they call the Controller "operations". The MVC abstraction has an issue with web applications, since the request-response cycle doesn't provide feedback as directly as the hardware-monitor-software cycle that the pattern was originally designed around. However, if the problem is that you are putting too much "logic" into your controllers, you should probably find a better place for it. I…

Yep. It's MVC with eventing (often found in most UI frameworks anyway). Definitely fits within the broad paradigm of MVC.

Re: MVC is dead, it's time to MOVE on

#228

Earlier quoted context omitted.

That's not inconsistent. A view is just an interface layer. Whether it's interfacing to a human or not is irrelevant.

This whole discussion is about MVC. In order to argue about MVC we should have a common understanding of the principles of MVC. MVC was invented by Trygve Reenskaug. His definition of MVC is both consistent and readily accessible. Therefore I have repeatedly referred to him for a definition of the components of MVC. Surprisingly, many of the posters don't seem to regard the inventor of MVC as much of an authority on…

Given the choice between admitting that one's comment wasn't well researched, and wasting thousands of eyeball hours with whatever-it-takes rationalizations about why one's comment actually was rather well thought out, most of us make the correct choice.

Unfortunately, the wrong choice comprises nearly half of comments made. You were obviously right the first time - let it lie :)

Re: MVC is dead, it's time to MOVE on

#229
post #214

Earlier quoted context omitted.

Converting the display format of data when requested by a view is exactly what a model is supposed to do. However, instructing a contained object to take some action at the user's request that is unrelated to display or management of contained objects is neither the responsibility of the view or the model, but specifically the task of the controller.

Ok, so let's go further. I want an email to be sent to me when the quantity on hand of a part gets below the re-order point. So now, I build a program that listens for notifications, and when it gets one, loads the data, erases the queue, and sends me an email. I build this so the app itself doesn't know this is required or is going on. Database triggers, queue tables listening scripts, and templates all are triggere…

This is very unclear - the database is not the model in the app, it's the storage for the model. (In its own application though, it may be a model...) You've abstracted some application functionality into the data storage, ok.

I'm speaking to the point that if you are separating Model, View, and Controller, and you have complex objects in your model that can do many things, it would not make sense to put all of the logic about what those things can do, how to do them, and when to do them in the model. Otherwise, you're simply blending the model and the controller (which may not be a wrong thing to do) - so you just have MV.

Let me give a more concrete example: I have a model which represents a network of connected complex "devices," there are five types of devices, each that can do 50 distinct things. The model can add a new device, delete a device, or retrieve an existing device. It can also ask the devices what their names, and addresses are, and what features they support, on behalf of any view which needs that information.

It cannot, however, tell device 1, which is of type X to take action "foo". That, instead, is implemented by a controller attached to a view that shows a big button that says "Do Foo", and a drop-down with the list of available devices that can do Foo. The view passes the press of the button onto the controller, which asks the model for the selected device, and then executes a "do Foo" command on it, and then, perhaps, contacts the device again to check that "Foo" was completed.

If all such logic were built into the model, I'd have several hundred methods in it, and I'd be very quickly looking for somewhere to move all of this logic, like, you know, controllers.

Re: MVC is dead, it's time to MOVE on

#230
post #229

Earlier quoted context omitted.

Ok, so let's go further. I want an email to be sent to me when the quantity on hand of a part gets below the re-order point. So now, I build a program that listens for notifications, and when it gets one, loads the data, erases the queue, and sends me an email. I build this so the app itself doesn't know this is required or is going on. Database triggers, queue tables listening scripts, and templates all are triggere…

This is very unclear - the database is not the model in the app, it's the storage for the model. (In its own application though, it may be a model...) You've abstracted some application functionality into the data storage, ok. I'm speaking to the point that if you are separating Model, View, and Controller, and you have complex objects in your model that can do many things, it would not make sense to put all of the l…

The database is not the model but the db operations are usually in the model, right?

My point though is in essentially shimming functionality. In my example, for example, here is how it would work.

1) User requests "save this invoice", which activates a controller script which automates the model elements for "invoice" instantiates an invoice (since this is a stateless web app) and saves it.

2) The model saves the invoice by writing it to the db.

3) Saving to the db fires a trigger which checks ROP vs on-hand and where ROP is greater saves a record in a queue table and issues an asynchronous notification, which doesn't have any immediate effect.

4) Controller commits the db transaction. The DB sends out the notification and makes the rows in the queue table visible.

5) Controller for application b wakes up (let's say every 15 min) and polls for notifications. Ok, we got one. Look up the queue table, prepare the email (model stuff) runt he template (view stuff) and sent it out (model stuff again).

So what I am getting at here is a way to have model events have side effects which are outside the scope of Application A, but are at least triggered by model operations. This is not an anti-pattern really because application A is not relying on those side-effects for operation. However if you look at application A as the primary one and application B as contained within it, then application B can only be described as contained within the model of application A, from application A's perspective, because all of its functionality is abstracted behind the model. From application B's perspective, there is a model, a view, and a controller, and it doesn't care as to where notifications and queue table data is coming from. From it's perspective it is a loosely coupled app in its own right.

But as always what I am suggesting is that common sense usually determines the best place for a given piece of logic. LedgerSMB is very model-centric but there are cases where we have a fair bit of logic in the controller.* I think that anything which is inherent in the model belongs in the model. So back to the vehicle analogy, a bike object should support a $bike->turn('l') and a $bike->turn('r'). However telling the bike when to turn left is the controller's job.

* for example in contact and employee management, the controller has to coordinate a lot of different model operations, leading to unusually long/complex model code in the system.

Post reply on HN