10 ms·
Client-side MVC is not a silver bullet
- prince_hakeem 14y agoWow, and I thought I was the only one that was thinking the emperor had no clothes but was missing something by not jumping on the client MVC bandwagon. All I saw was tons of extra complexity with very little payback for most apps.
- recuter 14y ago"We’ve spend a lot of time getting Backbone to work properly, and the ease-of-use quickly deteriorates when your models get more complex." It does not follow that client-side MVC as a whole is a dead end just because its easy to run up into the limitations of backbone.
- KaoruAoiShiho 14y agoRight on the money. The problem is backbone not client side apps.
- jrochkind1 14y agoWhile I have tended to be suspicious of Client-side MVC on the grounds they talk about... ...I'm curious why they are recommending Rails 2.3 and RJS, which are pretty much deprecated technologies. Rails 2.3 will stop getting even security patches when Rails 4.0 is final (first Rails 4.0 beta was released today). RJS has been discouraged in Rails for a while, and I believe is now a 'third party' gem in current versions of Rails. I had to double-check the timestamp in the URL to make sure this wasn't somehow an ancient post resurrected.
- ahoyhere 14y agoAfter years on the bleeding edge, our motto is: "Use what works. Don't faff about with shiny new toys which don't benefit the customer." Ask any of our customers if they care that Freckle is on the simpler Rails 2.x. Or ask patio11's customers the same thing; he agrees with us on how awesome Rails 2.x is. Also, Rails 2.x is NOT deprecated -- hence the spate of patches. Perhaps it will be, some day when Rails 4 is final, but given its popularity we'll all be extremely surprised if Rails 2.x doesn't live on as an independent and thriving fork. RJS is not everyone's cup of tea but it's not defective. What ships default with Rails reflects all kinds of political & other realities and isn't necessarily what is "best."
- venus 14y ago.. and after years developing, maintaining and administering rails apps, my motto is "never let your app get out of date". Rails 2.x is still functional, and still being updated, yes. It will very soon not be. And you've let such a gap open up that it's going to be a lot of work to catch up to where everyone else is. As an example failure situation you are opening yourself up to: one day, your server crashes. You quickly order up a new one, but the DB version will be newer and it won't work with your current db gem. You'll try to install a new one but it won't work with your old, old version of rails. You'll hurriedly look into what it takes to upgrade and realise it will take days, and you don't know anything about the weird new stuff. You'll try to install the old version of the DB but it's not even in the repo and so you ask for a couple earlier versions of ubuntu but they don't support that anymore and you've been down 6 hours now and is that "benefiting the customer"? Stay up to date. (edited to make it clear I was not talking about live-coding on a production server)
- ahoyhere 14y agoHow on earth do you get from "Rails 2.x will be deprecated sometime in the future, they say" to "your server is down 6 hours"? Do you think anyone reading this is coding (and updating libraries) live on the server? This is Rails, not PHP we're talking about.
- venus 14y agoI was talking about a catastrophic server failure, and the difficulty of timely recovering to an outdated software stack. Of course. Anyway, just trying to counter your terrible advice to use 2.3.x.
- ahoyhere 14y agoIf you don't have a system / recipe in place for rolling out new servers, having the newest framework is really not going to help you all that much. That said, we run our current Rails 2.x products on shared servers (Rackspace). Their default set up works just fine. You built up a horror scenario to prove your point, unfortunately it doesn't reflect reality / relies on a lot of assumptions about dev/ops incompetence that you didn't make clear.
- rhizome 14y agoFor the record, and this is supported by its absence in the linked post, nobody ever said it was a silver bullet. It's a rhetorical strawman that he doesn't bother knocking down, so don't get hung up on the title. That said, Charm appears to have had quite a bit of unnecessary platform spread. I smell cowboy-architecting (vis a vis cowboy coding), but it's hard to tell because he doesn't describe the process by which they chose to go the route they did, which would have added a ton more value to the post. Lastly, it's a little odd to me that he seems to contradict himself at the end, saying "don't repeat yourself," immediately after recommending the tools he's used for a long time. By my interpretation his implied moral to the story is, "we should have repeated ourselves."
- ahoyhere 14y agoHow could you know enough to accuse us of being "cowboys"? For the record, we chose carefully… after deciding to build fresh from what we had, to start with a live (client-side MVC) code base instead of shoehorning in AJAX interactivity here and there. The simple fact is: that was also the wrong choice. But it was carefully done. That's the whole point of the post.
- deleted 14y ago[deleted]
- dllthomas 14y ago'Lastly, it's a little odd to me that he seems to contradict himself at the end, saying "don't repeat yourself," immediately after recommending the tools he's used for a long time. By my interpretation his implied moral to the story is, "we should have repeated ourselves."' That's not what "don't repeat yourself" means. Building things using tools and patterns you've used before, refined by the experience, is a great thing (other things being equal). "Don't repeat yourself" means primarily "don't put the same info in multiple places such that differences between those copies is yet another thing that can break."
- madrobby 14y agoIt's marketed as a silver bullet. Here are some snippets from the ember.js Homepage: "Write dramatically less code", "Don't waste time", "Ember.js is built for productivity".
- lucisferre 14y agoI'd love to know what others are thinking in this space. I've flip-flopped a lot on this issue myself, looking at both sides I think good interactive web design is just simply hard no matter how you slice it. I've done Rails+PJAX along with minimalistic simple jQuery components (similar to Bootstrap's javascript) I think it works quite well for very simple content focused designs but falls short as interactions get more complicated. Lots of convinces that I find in modern JS-MVCs (Angular and Ember come to mind) are missing, like model-DOM bindings (so not Backbone). Now I'm playing around with AngularJS on something new and building that on top of Rails as an API (and for asset pipeline support which works quite well with Angular). This is also pretty good. Angular's style fills in a lot of gaps on the client-side that jQuery components did not. However I also see myself duplicating efforts in the views that would be more effortless on the Rails side. This is a side effect of different tools doing different things. I can't really take advantage of certain rails-isms if I choose this route, but the trade-off seems ok for me as I do feel it makes much of the interactive design on the client-side easier (so far, so good anyways). That said I don't yet feel like I can really come down on either side of the debate in terms of what is better for me. I do think if you switch in Rails for "client-side MVC" most of the author's statements are ironcially still true. Particularly the statement "they lock you into certain patterns" is arguably more true for doing everything the "Rails way" than for a good client-side MVC library. I do want to say two things. One, I've found Backbone to be the least productive of both of the choices I described above. It was a step up for a team with minimal Javascript experience, but once I understood the lay of the land I left it since I didn't really feel it was doing anything for me. Two, Backbone is definitely not what I would call a client-side MVC pattern. It lacks model bindings for starters. I'd like to see what the author thinks after some more time looking at the latest Ember or Angular. I'm also looking to see what happens with Flight as that is sort of a beefed up version of the components+events approach I had been taking before. Again, perhaps both approaches have their place depending on what your needs are. Addendum: When I was doing Rails+PJAX I sort of envisioned a concept where I delivered both data, layout and style with HTML+CSS (as semantic as needed) and used JS to handle interaction. Interestingly none of the MVC frameworks seem to support doing this very well (including Angular which seems best suited to the concept). Flight seems to which is why I find it interesting.
- 14y ago
- akoumjian 14y agoIt's not a silver bullet, it's a method to keep your sanity. What often happens is you start with a traditional server rendered web application. Maybe you have a couple ajax-y interactions for speed or UI responsiveness and everything is happy-go-lucky for a while. Over time, you find that you start wanting more data in more views, or large collections of items that you want to manipulate visually on the client side, with no need to bother on the server side. One by one, each view starts accumulating async, non-event based cruft. The callbacks become nightmarish. The JSON Api makes it easier to build those data heavy, complex views become more responsive. And they can change on the fly! The javascript MVC is a way to manage the the complexity and hopefully pairs well with a good event driven system. The point is, if you know your application is going to be sufficiently complex, it makes sense to build it as client side rendered to begin with. Other great benefits can include: - JSON API leaves you primed and ready to build native mobile apps or 3rd party integration - Your js developers don't have to wait for backend devs to modify half-complete ajax views if you have a good api - Your template rendering happens in once place instead of two, making it easier to isolate logic Obviously it's not worth the trouble if you only have a few models/resources and you are dealing with a very read heavy application. It is also a lot more work to implement two MVC layers instead of one, but you may sleep better at night.
- swah 14y agoAnother advantadge of client side is that you can work offline for some time, if needed, acting as if CRUD operations as working, say. OTOH: is any of the big complex successful websites, the ones that would most benefit from being written as SPAs, written that way?
- ahoyhere 14y agoWe DID build Charm with client-side MVC from the get-go. That's exactly the experience Thomas wrote about as being a problem. Note that Charm was not "read heavy" -- it was totally interactive and doing a lot of real work; we did live (email) thread locking and all kinds of crazy stuff. If we were to start from scratch, you can bet your ass we would keep the client-side as dumb as possible.
- 14y ago
- aymeric 14y ago1. What javascript libraries make working with server side rendering easy in a single page app? 2. It is a shame his blog doesn't accept comments. I wonder why is that? Who doesn't want the ability to discuss his ideas with his audience?
- jdross 14y ago"if you use something like Ember (which we didn’t), it’s even worse as all applications using it practically look the same (many people choose using Twitter’s Bootstrap library, for example)" wat? How does a choice of frontend framework like ember relate whatsoever to the look and feel of the application?
- logical42 14y agothat comment irritated me as well.
- deleted 14y ago[deleted]
- sheraz 14y agoOverall I tend to agree with the author's thoughts. However, I would like to say that just a dash of backbone and client-side MVC can make your site _feel_ more responsive without all the baggage of a single-page app.
- zackbloom 14y agoCalling it 'not a silver bullet' is very different than calling it wrong.
- srid68 14y agoUnfortunately the mainstream view is using client side rendering Good solutions are not only got from good problem definition, but also on the constraints imposed on the solutions. My constraints for my solutions, were separation of concerns (MVC/MVVM), and separation of skills (Conceptualizer/Designers/Developer/Mobile Native Developer) leading to the same conclusion as said in the article. I wanted my back end server (Need to run in Android/IOS/Shared Host/ to be purely API driven (REST/RPC) and my views templates to be mustache only and wanted to have the flexibility to merge the model to the view template in both the client as well as the server. As I spent more and more time on this architecture, i completely used server merging of models with type safe generated view template generated from plain html based mustache templates. As my dependency on Javascript reduced, i was amazed to discover that my performance started improving, I can independently regression test the API back end automatically by just capturing inputs/outputs to the API and I can think about the functionality independent of the UI. My belief is any architecture which gives both client side rendering as well as server side rendering using a Web API (REST/RPC) approach may be the ideal architecture as long as the view templates can be reused. This means we can mix in the same application, both client side as well as server side rendering. This is the approach i have taken to develop a cross-platform solution which works in Mobile/Server/PC environments using both Browser/WebView as well as OpenGL View rendering of UI.
- MatthewPhillips 14y agoInteresting post. I agree with one statement, many (not all) of the popular client side MV(not really C) libraries do lock you into a particular pattern. Especially Ember, Angular, Enyo... any with the scent of magic. That is what is most compelling about Backbone, it gives you the bare minimum, stuff you likely need anyways (the router and event emitter particularly). Not knowing about their setup I can't comment on why it didn't work for them. I have to wonder if they truly were developing 2 apps, as they said, or was it a mish-mash? I find that when you trying to blend a single-page app with a traditional multi-page app you run into the most issues. You duplicate a lot of logic because it's hard not to. In a true single-page app, the server doesn't need to be aware about the client at all. The server code should contain no views. It shouldn't even serve index.html in my opinion, nginx can do that far better.
- aymeric 14y agoI am currently working on a SPA using knockout.js and asp.net MVC in the back end. There is no server side rendering whatsoever. The performance is pretty good. The page does take some time in html parsing + js execution. But I think I can be smarter in the way I load my page to get some performance improvement while still enjoying the power of model/DOM binding from knockout.js Where the performance really starts to degrade is on mobiles, but I don't know if loading the html through ajax would be faster. Again, I think I need to be smarter in the way I load my DOM. I could have a index.html with the most initial page, and a remaining.html that I would download from ajax as soon as my initial page has loaded. This would allow the user to start using the app faster.
- tn13 14y agoSilver bullets have existed only in vampire fiction. In technology X->!SB is true for all X. Client side MVC is good enough in many cases. Where the app is small, rich in interactions and where the UI needs to evolve rapidly and where search engine optimizations, browser compatibilities (IE7 etc) don't matter much.
- tn13 14y agoHaving said that I settled for YAHOO Mojito. It is fairly young project but has the right approach.
- jacquesc 14y ago"I’ve come to the realization that this much client-side processing and decoupling is detrimental to both the speed of development, and application performance" While Fuchs is a credit to the early JS community, he's been railing against larger JS frameworks (including jQuery) for the better part of 4 years. He hasn't been proven right in practice. His approach of 100% server side generation may work well for some apps, but the clear trend is client side apps, with shared REST apis between mobile and web. Client devices are powerful, why do everything on the server? Let the server be the data store, and the UI rendering work on the client. Makes more sense, and is going to happen no matter how much Fuchs and his followers wish against it. [edited to be less antagonistic]
- madrobby 14y agoI'm Thomas Fuchs. That's interesting. How many apps have you developed?
- recuter 14y agoYour reply is about as good as his comment.
- ahoyhere 14y agoNot when you consider the original blog post, which addressed the question of "Why not let the server be the data store?" Among the other "points"[1] jacquesc raised. [1] anyone who wants to pretend to have a serious, rational discussion -- don't start it by calling the person a zealot. Bam! Insta-noncredibility.
- nkohari 14y agoTo be fair, he said he was "railing like a zealot" -- a subtle but important difference. Calling someone a zealot is attacking them as a person, calling their behavior "zealot-like" is only attacking the behavior.
- 14y ago
- jules 14y agoAll these issues would be solved if you work in the same language on the server and client with an integrated framework. The reason RJS and Turbolinks are so nice to develop with is because it allows you to do exactly that, though in a very limited way. For many applications you want to have a more featureless client-side framework. Ideally you'd share models and templates on the server and the client side; models on the client synchronized with models on the server, and templates automatically updating as models on the client side get changed (as you already have in many JS frameworks).
- seanconaty 14y agoDefinitely agree about double the work.
- rxcfc 14y agoIf it's double the work, you're doing it wrong. Possibly it's not a good fit for your specific case, or you haven't fully understood the best way to use it.
- seanconaty 14y agoThat is definitely true; there are different cases and I'm still figuring out the best way to use it. But I think even if your server is just a RESTful API (which I believe is the best way to work with bbone) the code you have for your models (both bbone and server) gets duplicated. The application logic must be on the server as a requirement for the API and if you want the logic to inform the UI, you need to write logic of the model in backbone too. It's similar to how you have to do form validation on the client/server. Take for example the simple model that some sort of a collection can only have 5 items. This rule has to be set somewhere in a model on the server. It also (should?) be set in a bbone model. If it's not, you could rely on the API's response code when you try to POST the 6th element, but isn't one of the benefits of a client side app supposed to be that you DON'T have to rely on the server for this kind of logic?
- rxcfc 14y agoThis is actually something I think can be solved. There have been some experiments in Ember with building Ember model definitions from the server model definitions. However, in practice I haven't found this to be much of an issue in my development.
- deleted 14y ago[deleted]
- pie 14y agoNo approach to technology architecture is a "silver bullet," especially with a stack spread across client and server. I always find myself returning to the "boring, old-fashioned" way of doing things (like server-side processing or relational databases) and these do indeed seem like the best choices for many applications. But I don't see how this calls client-side MVC into question, except that perhaps it's considered as a default choice too often.
- annymsMthd 14y agoI do client side "MVC" with backbone every day. With proper architecture the possibilities are limitless and far beyond what one can do with a simple server side architecture. Using ASP.Net SignalR + Rest API I can have a fully reactive front end with little to no effort on my part. I work in the transportation industry and I can track a large number of buses and react to situations entirely with javascript being fed by a Redis Pub/Sub. I believe this is the direction the web is heading and one should not simply brush it off.
- tjholowaychuk 14y agoCompletely depends on the type of app. Plenty of apps could t really be done any other way, and the client env doesn't have to suck, it just does because we keep building apps like it's 2000. Moar modules!
- ricardobeat 14y agoWhile I don't agree with the post, I have a feeling that we are not quite there yet with either Backbone or the data-binding pack (ember, angular, batman etc). After building three different products, two using Backbone, the least painful one was the one without a framework, purely event-based. One thing that I believe he is missing is the value of these frameworks paired to node.js - when the rest API behind the app is also javascript it all feels like a cohese project that crosses the server/client boundary, not a duplicated effort.
- emehrkay 14y agoIt's crazy how it went from "creating DOM nodes in JS is slow and shouldn't be done too often" to "lets do everything via the DOM and JS" in a matter of 2 years.
- csallen 14y agoAlthough client-side MVC may indeed have been a bad choice for the development of Charm, I disagree with the author's conclusion that it's an inferior design pattern for SaaS web apps as a whole. Most of his criticisms are invalid: >> ...and if you use something like Ember (which we didn’t), it’s even worse as all applications using it practically look the same This seems strange to me. Client-side MVC frameworks like Ember and Backbone have absolutely no effect on the appearance of your application at all. >> We’ve spend a lot of time getting Backbone to work properly, and the ease-of-use quickly deteriorates when your models get more complex Backbone is imperfect, but this is hardly a point against client-side MVC as a whole. >> What you end up with is building a layer cake that doesn’t add any value and slows down development. Especially when you’re starting out and need to stay flexible you don’t want to have too much code around—and Rails is great for that, but… adding a JSON API layer and basically a second application that runs on the client is annihilating this advantage for you. This, I think, is his strongest point. There certainly is extra code you need to write for applications that rely heavily on front-end code. But, on the flip side, there are advantages, too. For example, you tend to have a significantly snappier user interface without having to resort to complex and error-prone nested caching schemes. There's also the beneficial side-effect that you'll end up testing your JSON API very robustly. At the end of the day, the "correct" answer is likely the boring one: the pattern you should use depends heavily on personal constraints such as who you are, what you're familiar with, and what you're building.
- jaequery 14y agoi'm not sure who is right (having been in both sides of the issue) but we can all agree on this one thing. client side MVC frameworks like backbone.js, knockout, angular, have helped front-end devs earn a "lot" more money than ever before. so you really can't fault them for using these frameworks regardless of if it's good or bad. :)
- ahoyhere 14y ago> For example, you tend to have a significantly snappier user interface without having to resort to complex and error-prone nested caching schemes. Depends on how you define "snappy"… the ability to use a lot of seemingly live interactions? Yes, but… We found that all the client-side templating was a client-side slow-down. Charm did not have a ultra simple UI like Twitter (not that they're a fabulous example of client-side MVC success, but there you go). Which is why sending packets of HTML would actually be faster. Insertion of HTML is faster on the client-side. The exception would be if you're sending a LOT of HTML, vs the amount of bits the JSON formatting takes up. Depends on where the complexity is. We didn't have server-side performance problems for rendering.
- hoodoof 14y agoDoesn't Rails lock you into certain patterns more than just about any other back end framework?
- gurvinder372 14y agoLooks like author is simply taking a dig at what is becoming a popular technical cliche these days. MVC is a proven design pattern for web-application's server side, and the server side tends to be less context specific or not as much as client side does. Client side design needs to be as much as context specific as possible for not only performance improvement but also effort required for the learning curve. If an application doesn't have the complexity of too many views, then MVC doesn't make any sense. Future scalability is just another argument which is thrown around without keeping in mind the context. However, I do realize that doing an entire business app in JavaScript could be tough for people new to this technology. For those people it become a bit more easier to understand and estimate the effort if they know a fancy framework which can do a few things out of the box for them. So, using client side libraries do have their benefits too. So, I guess it all depends on the context and the existing skill-set of your development team.