One of the cool features of C#, or more precisely the .NET Framework, is the Data Binding concept. Basically, it means that you can bind two objects together, and they would notify each other of changes in their internal data automatically. In practice you’d bind a view (say, a grid) to a model (say, a table), although it can (and does) get more versatile than that. The result is a lot of abstraction in the model-view relationship, which saves a lot of time and grief. This is a feature which seems unique to C#, and kicks some major butt. [Edit: it was pointed out to me that Delphi had data binding since the 90s.]

Of course, it’s not (always) a bed of roses. Behind the scenes data binding is a pretty complex business, although it may seem much simpler to the programmer. And there can be bugs. Oh, the bugs…

A really nasty (in that I couldn’t even track down its actual cause) bug involves binding a custom property of a UserControl (in my case, to a data view) . While selecting different rows, I noticed that their RowState was changed to Modified, even though the actual values remained the same. Closely inspecting my custom control, I found no faults. (No data was changed – I carefully monitored the bound property with the debugger, simplified it to a trivial variable set/retrieve, etc.) This did not happen with regular controls (TextBoxes, etc.). I worked by the book, but it didn’t help.

Frustrated, I eventually stumbled upon this exchange. The solution was to switch to a different protocol on the client side – implement the Framework’s INotifyParentChanged interface. It worked for me as well, but I think it’s inferior to the old way of defining a FooChanged event to go along with the Foo property. But the real question is – why did it work, when the old way didn’t? (An interesting symptom of the bug was that the binding didn’t sign up to the event I declared, although it should have, to monitor changes.)

I still have some doubts over this bug, though. Since our system does funny things with the binding internals, I don’t really know if this is a Framework bug or not. Didn’t have time to make a minimal example out of it yet, although I will. I will also be sure to report my progress. It will make me kind of proud if this indeed turns out to be a Framework bug, and I’ll be the one to file the report ;-)

During the hellish time I had in the programming course I took in the army, I wrote a poem to describe my sheer agony. Well, actually, it wasn’t that bad, but the poem is still true (and amusing, I hope). One thing, though – the author does not really share the sentiment expressed in the conclusion, although it’s possible to see how that much misery could drive one to such extremes ;-)

Segfaults left and right,
I admit I’m not that bright
To follow every “new” with a “delete”.
I wish there was protection
In the form of garbage collection,
Otherwise my programs with bugs will be replete.

Low level languages are pro’ly not for me,
They bring me nothing but pain and misery.
Too many lines of code -
My head will soon explode!
Give me Python, maybe Icon, just not C!
(But apparently, we’ll only get VB…)

And now I’m getting bored
With Excel and Word -
They make us write the answers
In stupid pseudocode.
I wonder if they know it,
I really do deplore it,
I’ll axe them all when the course is done,
I really ought to have some fun,
I’ll take ‘em out one by one,
‘Cause programming – it ain’t for me!