[Gtk-sharp-list] Associate user data object with a widget

Chuck Esterbrook chuck.esterbrook at gmail.com
Thu Nov 26 14:35:08 EST 2009


On Thu, Nov 26, 2009 at 3:49 AM, Chris Howie <cdhowie at gmail.com> wrote:
> On Thu, Nov 26, 2009 at 6:37 AM, Chuck Esterbrook
> <chuck.esterbrook at gmail.com> wrote:
>>> The reason that the "user data" mechanism is marked obsolete is
>>> because it's completely the wrong way to model something like this and
>>> usually creates more problems than it solves.
>>
>> Putting a value in a hashtable owned by an object isn't much different
>> than putting a value in a variable owned by the object. In fact, some
>> languages like Python even store their object variables using a
>> hashtable!
>
> Comparing Python to a tag/data property is comparing apples and
> oranges, see below.

Given that GLib.Object's UserData is returning a Hashtable, it's
actually almost the same thing with the same pros (flexibility and
rapid prototyping) and cons (potential collision, misspelled name and
lack of typing) that you mentioned further in your reply. Python
objects have those very same pros and cons.

>> There are several GUI framework authors who think user data is okay
>> given that GUI libs tend to have this feature including GTK+,
>> WinForms, WPF and Silverlight. See also:
>> http://stackoverflow.com/questions/1058635/common-uses-for-the-tag-property
>>
>> I've used this technique in other GUI libs without experiencing a
>> single problem. It's just an alternate way to stash data in an
>> existing object.
>
> The main problems with this approach are type safety and collisions.
> ...

I understand your extreme dislike for it and won't argue against you
here. I just feel that if it's available in the GTK+ library to C
users, then it should also be available to C# users without Obsolete
attributes and scary documentation about garbage collection disasters.

Let the developer decide.

-Chuck


More information about the Gtk-sharp-list mailing list