3 ms·
>If not, What is the correct answer that will prevent me from getting COMPLETELY EXPOSED (in your words) if you ask me this MVC question in an interview? Every
by fsk 12y ago
>If not, What is the correct answer that will prevent me from getting COMPLETELY EXPOSED (in your words) if you ask me this MVC question in an interview?
Every interviewer has their own pet question that the candidate is COMPLETELY UNQUALIFIED if they don't know.
My short answer to "What is MVC?" is that it's a popular web development trend, but without much substance to back it up. Every MVC project that I've been supporting/maintaining was a nightmare, taking 3x-5x longer to get stuff done than what I consider reasonable.
MVC = Model-View-Controller. It's usually for web development. You structure your code in a way that separates the data logic (Model), the user presentation logic (View), and the glue that holds the bits together (Controller).
There are many popular MVC frameworks that let you churn out a lot of mediocre websites quickly (angular.js, Ruby on Rails, Zend, Django(Python), and many others). The MVC framework does a lot of routine coding for you, but it comes at a price. The code can become a nightmare to maintain, especially if you use the MVC framework incorrectly. If you do something outside what the MVC framework provides, it can become a handicap rather than a help. The MVC framework usually demands you write your whole application in its preferred style, such as spreading out your code in various directories with forced naming conventions. MVC frameworks tend to be poorly documented compared to the underlying language (For example, compare the zend documentation to php.net).
- ExpiredLink 12y agoBTW, there isn't just one MVC pattern.
- fsk 12y agoYeah, I know, angular.js is MVVM and not MVC. It still sucked. The boss chose angular because he wanted to pad his resume with angular.js experience, and not because it was the right tool. That startup is still stumbling along, but wasn't as successful as it should have been. (In angular, when you edit data in the view, the model is immediately updated, which is why it's MVVM and not MVC.)
- slowmovintarget 12y agoFunny thing... MVC is a pattern for GUIs (Windows and Mac desktop applications). It was simulated for the web, and none of those that you mention with the possible exception of Angular allow a real MVC pattern in a web application. The point of it is two-fold: separation of concerns, and DRY. But the reason it so ugly on the web when it produced elegant code for GUIs is the reason that web controller schemes are not MVC.
- SomeCallMeTim 12y agoActually, it never worked in Windows GUIs either. [1] It's just a broken concept. Separation of concerns and DRY are both good. MVC doesn't succeed at either, except in idealized corner cases. [1] A lot of widgets in Windows, for instance text fields, encapsulate the view (it's where the text is displayed), the model (which keeps the text in the control), and the controller (the widget handles the UI for entering text, catches and handles the mouse, etc.).
- simoncion 12y ago> Funny thing... MVC is a pattern for GUIs (Windows and Mac desktop applications). Errm, it's a pattern often used for UI (CLI and GUI) programming that was first commercially introduced in Smalltalk-76 (in 1976). [This predates Windows and Mac by many years.] MVC can be done -with varying degrees of difficulty- in any computer language. You don't even need a web development framework to implement it! ;-)
- TheOtherHobbes 12y agoJust because it can be done, doesn't mean it can be done well. iOS/OS X seems to do real MVC, with lightweight reusable view objects managed by ready-made controller classes. The obvious benefits are minimal memory and streamlined data flow. You only ever make/use the view objects you really need, you can recycle them to save memory, and - in OS X especially - controller objects include useful ready-made convenience methods. Web frameworks often seem to do something that looks like MVC if you squint and don't think too hard. But when you're forced to use separate languages for logic (js), markup (HTML), and view design (CSS), and handle separate client/server environments, and there's inevitable overlap between all of the above (jquery etc) because stuff doesn't "just work", and you probably have yet another layer as a DB driver, it gets very complicated very quickly - to no great benefit. The web has become a snarly ball of warty epicycles. That's why native is so popular - you get one common language for logic, views, and data, with a clean-ish interface to a remote server if you need one. When everything works together like that, you can think seriously about MVC. When the core concerns are all over the place already, it's a mess before you even start. Which is not to say you can't work with it and build cool stuff - more that you can't just airdrop in a design pattern from a different tradition without thinking really, really hard about what, why, how, and what happens a year from now.