8 ms·
JSON and RSS views don't make sense - in MVC, views are visual representations of data (the model). Views are how the user percieves the application. JSON and R
by blahbap 14y ago
JSON and RSS views don't make sense - in MVC, views are visual representations of data (the model). Views are how the user percieves the application. JSON and RSS are just different methods for representing data to be communicated to other systems.
- blowski 14y agoUsers are not necessarily human - they can be search engines, API consumers, etc.
- blahbap 14y agoIn the context of MVC, a user is a human being - describing JSON and RSS services as "views" totally misses the point. Quote from the inventor of MVC, Trygve Reenskaug: "The essential purpose of MVC is to bridge the gap between the human user's mental model and the digital model that exists in the computer."
- jshen 14y agoI'm a human user and I have a mental model of the json and rss apis I consume via code I write. I notice that he didn't say visual as you did earlier
- blahbap 14y ago"A view is a (visual) representation of its model. It would ordinarily highlight certain attributes of the model and suppress others. It is thus acting as a presentation filter." Source: 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 And you are not a human user, you are an engineer.
- jshen 14y agoYou keep using an appeal to authority, and I still see no value in the distinction. I am most certainly a human user.
- alexro 14y agoIf you're so keep on giving a different meaning to already defined standard why not use some other abbreviation, say MRC (R for Representation)
- jshen 14y agoMVC is not a standard. I also don't find it useful to have different names for ideas that are effectively the same with some distinction that doesn't seem to make a difference. Maybe there is some significant difference, but you haven't outlined one other than "it's not what person X says MVC means".
- jcarreiro 14y ago> JSON and RSS are just different methods for representing data to be communicated to other systems. We call those, "views".
- Androsynth 14y agoIn an MVC, the views are used both for output of the model and to map input back to the controllers. Without the input, its not part of the MVC pattern.
- TylerE 14y agoBullshit. Please show me your Rails-or-similar app that's doing INPUT parsing in the view (embedded JS doesn't count)
- Androsynth 14y agoWhen you click a link on a web page, it gets routed to a controller action. Thats done because the link was generated with the url: example.com/controller/action. Its not about parsing input, its about routing.
- melvinmt 14y agoIt's the browser who renders anchor tags clickable - if you click on a link in a RSS reader you also get routed.
- randomdata 14y agoHATOES says that your XML/JSON/whatever needs to have those same links. What is the difference between an <a href=""> link in HTML and a { action_url: "" } property in JSON?
- Androsynth 14y agoNothing I suppose. I don't think that html vs json was what MVC's[1] creators had in mind for it, but if the json is rendered in such a way that it has links pointing back to the controller, it is a view. [1] Although were talking about Model 2 here, so thats irrelevant. Come to think of it, this whole discussion is pointless: we're arguing about whether views in a Model 2 architecture are proper MVC views...
- deleted 14y ago[deleted]
- jshen 14y ago"views are visual representations of data" I see no purpose for this distinction. A view is an output representation of the model data. Given the challenge, "How much of my code survives if I drastically change the view?", I think json and rss make perfect sense. They are drastically different output representations of the data.
- FuzzyDunlop 14y agoHTML is also one of those different methods. It just so happens that the browser renders it instead of spitting out the raw text. That said, non-HTML output bypasses the view entirely in Rails (it makes sense to), so it can equally be the case that the distinction is correct.
- jshen 14y agorails is moving towards a "view" based approach. Here is one of the up and coming libraries. https://github.com/rails/jbuilder/ https://github.com/rails/jbuilder/ It looks a lot like a view file :)
- sophacles 14y agoSo it's only a view when you write all your code to push bits to the monitor yourself. Outputting using libraries that convert formats like html (-> browser -> os/driver -> screen) aren't views. Got it.
- blahbap 14y agoLet me give you an example. In your model, you have represented the salary of an employee as an integer. In a web application, the salary can be presented to the user through numerous different views - as a number on the screen (plain HTML), as a slider (jQuery UI slider), as a bar in a bar chart (using some charting library). The tools you use to build the view are not relevant.
- HeyImAlex 14y ago> In a web application, the salary can be presented to the user through numerous different views - as a number on the screen (plain HTML), as a slider (jQuery UI slider), as a bar in a bar chart (using some charting library) as JSON encoded output, as XML....
- Androsynth 14y agono, those output types dont map back to the controller, they are not views.
- alttab 14y agoRestful Apis often times can return JSON with key value pairs for subsequent actions in the form of name: URL. While you can't click on JSON, it's a "view" for the consumer application because it can follow back into the controller. The distinction is that a view doesn't necessarily need to be a human reading a screen, and can most certainly be another application.
- sophacles 14y agoOhhhh, I see now. So some data formats that render to screen through external software are views, like html, json, generated javscript or xml if they go through jQueryUI or charting libraries, but if it goes through other external software like RSS readers, or non html, json, or javscript formats, before making it to the screen, it is no longer a view. Thanks for the clarification!
- corford 14y agoNot saying I disagree with you but then where exactly would the JSON and RSS output methods go in an MVC framework, if not in a view i.e. how would a different system or user consume/access their output? Directly from a controller? Would love to know your thoughts as I've always found MVC a difficult conceptual approach to grok when applying it to web apps (lots of code never seems to have an obvious M, V or C home).
- deleted 14y ago[deleted]
- blahbap 14y agoServices that provide data as JSON and RSS are not part of MVC at all. Even if you use MVC for your application, not _every_ part of your application has to fit into MVC. You use MVC only for the part of your application that communicates with the user. Other parts of your application, like external APIs, should not be crammed into any of your MVC components. A service that provides RSS or JSON on request would simply fetch data in a database and send it along, bypassing all your models, views and controller entirely. (Note that the database is not considered a part of MVC).
- jrgnsd 14y agoI'm not 100% sure where it fits in, but I tend to write have a Formatter service that is used by the controller to pass the model to the correct view. The Formatter inspects the Request to determine what format it should be (html, json, xml, etc.), and returns the correct View to the Controller, which then passes the Model to that View.