Aaron Feng

Friday, May 05, 2006

Databinding is EVIL

Ok, I am officially done with databinding. Today I was working with Steve on a piece of fairly trivial code, all we wanted to do was dirty checking on a few controls and provide the ability to roll back on a simple form. We poked around in the designer, and clicked here and there, then changed a couple lines of code. Overall it was very annoying, and very repetitive work because the databinding was acting flaky. Eventually we got the dirty checking on a modal form to work correctly. Before we checked in, we smoked the application real fast just to make sure everything was still working. We clicked around for a few seconds, we noticed the dirty checking was not working correctly sometimes, but we could not pin point the exact cause. By chance, we figured out the problem. If we move the modal form around on the screen after changing a value in a combo box, databinding goes nuts which breaks the dirty checking. For the most part of the day, I thought I was high because one second databinding was working, next it was blowing up.

We have been feeling the pain on databinding for a while now. I even wrote databinding on our house of pain white board, when I thought I understood databinding. We decided to stick with it because datatbinding makes things "look" so easy. It is like magic. The problem with databinding is it makes something that is very comoplex under the covers to appear stupid simple. Almost every example found in any book or on the Internet uses databinding. It seems databinding is the way to go. Databinding works fine if you have very simple UI that does nothing but display data in a primitive way. Soon as you introduce complex and rich UI, databinding makes things much harder. If databinding is so easy to use, why is Brian Noyes' book "Data Binding with Windows Forms 2.0" 696 pages? There is a lot more to databinding than what meets the eye, which can lead to some serious disconnect between team members. This can often lead to dangerous situations when the wrong assumptions are made. Before you know it, you are adding hacks, so databinding would work correctly as you would expect.

The predictibility of databinding is very low because not all controls behave the same way when databinding is used. Duplication is one of the worst things you can do in any program. The concept of what value the control is displaying is duplicated. For example, if you want to retrieve data in a combo box, do you get it from the binding source or from the control it's self? The worst part of all is the value displayed in the control can be out of sync with the underlying binding source.

I hope this does not sound like I am ranting, because I am not. Maybe I am old fashioned, but manually populating the controls will be much easier and more understandable. On top of that, the code will be more testable. Less magic is a good thing.

5 Comments:

  • This is the feeling I have been getting for a while now. It seems like any time Databinding is involved we have day long sessions why #*#@ won't this work right and we never seem to get any closer to understanding and using it predictably as a team.

    By Anonymous Nick Goede, at 5/05/2006 11:13 PM  

  • Spot on. I, too, have long hoped databinding would work like advertised, but it never seems to. I've basically given up on it for everything except datagrids.

    By Anonymous Chris Holmes, at 5/07/2006 9:30 PM  

  • I was also thinking about that last night. Databinding on datagrid seems to work fine. That is a good thing because populating datagrid by hand is not an acceptable solution.

    By Blogger Aaron Feng, at 5/08/2006 11:12 PM  

  • I realize this is a year late... but I agree whole heartedly.

    Every day that I think, "Hey I finally understand data binding," I get some new problem pop up. I think there are too many assumptions of
    a) The programmer's knowledge of the data binding mechanism
    b) the object model
    c) the usage scenario

    I made a recommendation to the development team early in the project to go with data binding, and some days I regret my decision, because I spend so much more time debugging and troubleshooting, for example, comboboxes that don't update the underlying datasource when it is nullable, etc...

    Despite the duplication, I think that a traditional paste and scrape method is far superior because it gives greater control to the programmer and is 100% reliable. Hell, even DoDataExchange from MFC is better.

    Some days I bang my head on my keyboard and ask, "why does this have to be so complicated? I just want to put a value on the screen..."

    These days, when there are new technologies coming out of Microsoft every month, I just don't have the time to scratch my head and wonder why nothing works, and I still have to attach a delegate to OnSelectionChangeCommitted and manually set the value...

    By Blogger Alex Steger, at 5/01/2007 4:55 PM  

  • Yeah. Agreed. It is a big waste of time masquerading as an efficiency boost. In this respect there are many traps in the modern platforms that will temp you from the straight and narrow pursuit of quality.

    By Blogger Fasty, at 12/14/2008 12:54 PM  

Post a Comment

<< Home