<p>Another discussion (we've been having a lot of them these days!) in our work is whether data binding is a bad idea or not.</p>

<p>Personally, I think it is a Bad Thing™.</p>

<p>My reasons are thrice:</p>

<ol>
<li><p>It circumvents my well architectured MVP framework - with databinding, the view communicates bi-directionally with a model.  Ewww.</p></li>
<li><p>It promotes hooking up view controls to datafields at design time.  In my experience, this leads to vital code (binding column A to Field X) being obscure and hidden away in some designer file.  IMO this code should be explicit and in-your-face, so that it is easy to modify and see what is going on, without having to use a clunky designer interface.</p></li>
<li><p>Relating to Point #1 this direct binding makes it harder to isolate each component (view, model, controller/presenter) and unit-test.  </p></li>
</ol>

<p>The pros are that it is easy to set up, and you can take advantage of some nice features (validation etc) which come with the plumbing already done for you.  </p>

<p>But for me, databinding becomes much more of a hindrance when dealing with a large data-centric application.</p>

<p>Any thoughts?</p>

[{'answer_id': 19488, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 2, 'selected': False, 'text': "<p>@Point 1: Isn't the data binding engine the controller, if you really want to think in patterns? You just do not program it yourself, which is the whole point of using data binding in the first place.</p>\n"}, {'answer_id': 19489, 'author': 'Guy', 'author_id': 993, 'author_profile': 'https://Stackoverflow.com/users/993', 'pm_score': 3, 'selected': False, 'text': '<p>As we say in the UK, <em>"It\'s Horses for courses"</em></p>\n\n<p>First off all, I agree with you! But...</p>\n\n<p>For enterprise level applications, then spending the extra time on the system architecture, modelling and standards will give you a robust and sustainable system.</p>\n\n<p>But it will take longer to develop (or at least longer to get to an initial release) and this may not be appropriate for every system or every part of the system.</p>\n\n<p>Sometimes you just need to "get it done and done quick".  For internal applications, back office systems and maintenance applications that are rarely used or very dynamic (the spec\'s change often) then there is little justification in building the Rolls Royce solution for this.  It\'s better to get the developer spending time on the CRITICAL part of the system.</p>\n\n<p>What you have to avoid / prevent is using these "one click framework" solutions on the MISSION CRITICAL area\'s of the system where the big transaction rate area\'s and where data quality and integrity is critical.  Spend quality time shaving the milliseconds off on the most heavily used area\'s on the system!!</p>\n'}, {'answer_id': 19494, 'author': 'Duncan', 'author_id': 1193, 'author_profile': 'https://Stackoverflow.com/users/1193', 'pm_score': 0, 'selected': False, 'text': "<p>@Timbo:</p>\n\n<p>Yes and no.... but from a TDD perspective I'd like to cordon-off each controller so that I can test it in isolation.  Also, say we want to run each edit via an EditCommand (so that we support Undo, for example) - for me, this rules out databinding.</p>\n\n<p>@Guy:</p>\n\n<p>Yes, this is exactly my POV.  For me, databinding is great for very simple apps, but we don't do any of those!  </p>\n"}, {'answer_id': 19598, 'author': 'Roland Tepp', 'author_id': 1712, 'author_profile': 'https://Stackoverflow.com/users/1712', 'pm_score': 2, 'selected': False, 'text': "<blockquote>\n  <p>Another discussion (we've been having a lot of them these days!) in our work\n  is whether data binding is a bad idea or not.</p>\n  \n  <p>Personally, I think it is a Bad Thing™.</p>\n</blockquote>\n\n<p>Strong opinion, but imho, you bring out all the wrong reasons.</p>\n\n<ol>\n<li><blockquote>\n  <p>It circumvents my well architectured MVP framework - with databinding, the view communicates bi-directionally with a model. Ewww.</p>\n</blockquote>\n\n<p>I guess it depends on the implementation of the data binding.\nIn the early years of my programming career, I used to do a lots of VBA for MS Access programming and Access forms had indeed this direct binding to tables/fields in database.</p>\n\n<p>Most of the general purpose languages/frameworks have databinding as a separate component, do not use such a direct binding and are usually considered as a easy generic dropin for a controller in MVC pattern sense.</p></li>\n<li><blockquote>\n  <p>It promotes hooking up view controls to datafields at design time. In my experience, this leads to vital code (binding column A to Field X) being obscure and hidden away in some designer file. IMO this code should be explicit and in-your-face, so that it is easy to modify and see what is going on, without having to use a clunky designer interface.</p>\n</blockquote>\n\n<p>I guess you are talking about the binding in WinForms?</p>\n\n<p>My experience with win forms comes from a long ago, so I might be pretty out of date here.\nIt sure is a convenience feature, and I would strongly argue against it, unless you are writing really simple modal context CRUD style interfaces.</p></li>\n<li><blockquote>\n  <p>Relating to Point #1 this direct binding makes it harder to isolate each component (view, model, controller/presenter) and unit-test.</p>\n</blockquote>\n\n<p>Again - assuming the view (a widget in WinFoms?) is tied together with databinding awareness, you are right.</p></li>\n</ol>\n\n<blockquote>\n  <p>But for me, databinding becomes much more of a hindrance when dealing with a large data-centric application.</p>\n</blockquote>\n\n<p>Quite contrary - if data binding is implemented as an independent component (eg. bindings in Cocoa or JFace DataBinding, or JGoodies Binding), that acts as a controller between View and a Model, taking care of all the nitty-gritty of event handling and conversion and validation, then it is just so much more easier to use, change and replace than your custom controller code doing just the same thing.</p>\n\n<p>The only downside of a general purpose data binding framework is that if the binding is off and/or misconfigured, the interactions between bound pieces are just notoriously difficult to debug due to the level of abstraction inside the data binding code... So You better not make any mistakes! ;)</p>\n"}, {'answer_id': 90636, 'author': 'J D OConal', 'author_id': 17023, 'author_profile': 'https://Stackoverflow.com/users/17023', 'pm_score': 0, 'selected': False, 'text': "<p>I feel that in many frameworks, data binding is just an excuse to do things the easy way. It often results, as does almost any designer-generated code, in too much code which is too complicated and can't be easily tweaked. I've never come across a task I couldn't do just as well (if not better) and, in most cases, just as quickly, by data binding as by writing the code myself.</p>\n"}, {'answer_id': 560997, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I have used databinding on large enterprise systems inconjunction with a framework. In my case it was CSLA.</p>\n\n<p>It worked so well, and was extremly fast to get the view working. CSLA has lots of support for databinding and validation built in though.</p>\n\n<p>If it breaks the MVP patturn, so what? if it works better and faster and is easier to manage. However, I would argue that it doesn't break the patturn at all... You can hook up databind in the presenter as it has a reference to the view and also to the model.</p>\n\n<p>for example this is what you would put in your presenter and it would populate the list box or whatever control you want.</p>\n\n<p>myView.list.datasource = myModel.myCollection;</p>\n\n<ul>\n<li>Also I would like to point out the databinding shouldn't be taken as an all or nothing approch. Many times I use databinding when i have a simple and easy UI requirment to map to my object model. However, when there is special functionality needed I might put some code in the presenter to build up the view as I need it rather than using databinding.</li>\n</ul>\n\n<p>Alan</p>\n"}, {'answer_id': 663652, 'author': 'Bevan', 'author_id': 30280, 'author_profile': 'https://Stackoverflow.com/users/30280', 'pm_score': 2, 'selected': False, 'text': "<p>I've used databinding in some pretty large systems and find that it works pretty well.</p>\n\n<p>Seems that I do things a bit differently from you though ...</p>\n\n<p>... I don't databind to the model, instead to a dedicated view class that works as an adapter between the model's structure and what I need on screen. This includes things like providing choices for comboboxes &amp; listviews, and so on.</p>\n\n<p>... I never set up the binding using the UI. Instead, I have a single method (usually called <code>Bind()</code> or <code>BindXYZ()</code> that hooks everything up in one place.</p>\n\n<p>My Model remains agnostic, knowing nothing about databinding; my Presenter sticks to the workflow coordinate it's designed for; my Views are now also simple classes (easy to test) that encapsulate my UI behavior (is button X enabled, etc) and the actual UI is relegated to a simple helper on the side.</p>\n"}, {'answer_id': 6870839, 'author': 'Sebastien Lorber', 'author_id': 82609, 'author_profile': 'https://Stackoverflow.com/users/82609', 'pm_score': 0, 'selected': False, 'text': '<p>I quite agree with you, data binding have drawbacks...\nIn our application, if not used carefully, it leads us sometimes to bad data consistency...</p>\n\n<p>But there may be some elegant ways work with databinding with large forms?</p>\n\n<p>Please give me your opinion here:\n<a href="https://stackoverflow.com/questions/6858935/clean-way-to-launch-multiple-actions-with-a-binding-framework">How to use a binding framework efficiently</a></p>\n'}, {'answer_id': 11439734, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>No. DataBinding <em>when used correctly</em> is a Good Thing™.</p>\n\n<ol>\n<li><p>No; but see #2 and #3. Make the Presenter expose the properties/well-defined sources to bind. Do not expose the Model. Nothing is circumvented.</p></li>\n<li><p>I agree. I do not use <em>any</em> of the standard ASP.NET data-sources. Instead I use GenericDataSourceControl which is wired to a "select method" that returns well-defined types. The DataSource consumers in the View only knows of these Presenter-types; nothing more.</p></li>\n<li><p>No. Relating to #1. The Presenter exposes the properties/well-defined sources to bind. These can be tested without the view for correctness (unit tests), and with the view for correctness of application (integration tests).</p></li>\n</ol>\n\n<p>(My Experience is using ASP.NET WebForms, which may differ from other data-binding scenarios.)</p>\n'}, {'answer_id': 18711483, 'author': 'Garth Pickell', 'author_id': 2442681, 'author_profile': 'https://Stackoverflow.com/users/2442681', 'pm_score': 2, 'selected': False, 'text': '<p>I have had a few unshakable realizations about data binding over the last few years:</p>\n\n<ol>\n<li><p>The claim that the data binding allows for the business and presentation to be designed in isolation of each other is actually really quite far from what actually goes on in reality. Usually the deficiencies in the technologies become readily apparent and then all you have done is break apart the UI from the UI-specific business and the resulting separation often becomes far more unwieldy than a all-in-one approach.</p></li>\n<li><p>Most data binding engines (HTML / WPF / or whatever) all make assertions on the technical business model, and since the designer is not usually equipped to make said assertions, the developer ends up having to touch the view. Not only that, the view shouldn\'t be making assertions about the business model---if anything, it should be the other way around.</p></li>\n<li><p>Most of the time, the view model / controller / model / view are all "coupled" and then all you have really done is "move code around" rather than just simply using code behind. With that said, I do find the most pragmatic approach is often to just use data binding sparingly with code behind and forget about MVVM/MVC esque patterns.</p></li>\n<li><p>Developers often put view level concerns on the view model and then start to use data binding as a crutch rather than a proper approach. for example, I have seen so many view models controlling visibility of UI elements.</p></li>\n<li><p>Admittedly, data binding is useful for "small systems". I have observed that the performance, complexity and maintainability dramatically suffer as an application grows in richness. </p></li>\n<li><p>Memory usage techniques with data binding can often become a real hazard. WPF for example uses a LOT of trickery to avoid issues and often developers can still shoot themselves in the foot. Unless you are using something like Sencha for HTML (I think), you will find your memory foot print on your applications start to suffer even with a modest amount of data.</p></li>\n<li><p>I have found that data binding / UI patterns in general sometimes tend to break down a little when dealing with hierarchical and situational data / presentation.</p></li>\n</ol>\n\n<p>My personal outlook on data binding is that it is a tool that can be easily abused yet has some compelling uses. You can say the same for any technique, pattern, or guideline. Like anything, too much of something tends to become a problem. I tend to like to try and use the most pragmatic approach for the situation. Prefer consistency when it is pragmatic to do so, but consistently be pragmatic. In other words, you don\'t have to go down the path of developing for two years and only then come to the conclusion that the code base has become a grotesque smelly mammoth in a china shop full of orphan kittens.</p>\n\n<p>...</p>\n'}]
['https://Stackoverflow.com/questions/19481', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1193/']