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

Andy Selvig ajselvig at gmail.com
Fri Nov 27 00:27:00 EST 2009


I've been reading this conversation, and just figured I'd give my two cents.

I have to agree with Chris 100% on this. First off, comparing it to
Python is a bit apples/oranges. Even though a hashtable approximates
Python property system, that is the "Python way" to do things. It's a
dynamic language and people use it for situations where they're okay
with no type safety or collision avoidance.

The argument that it's "okay" to C users is a bit misleading as well.
One of the best things about C# (and Java) is that it actually has a
strong runtime type system. The C type system is a compiler
convenience that can mostly be ignored by the developer if they
choose. For example, I could store some user data in C that's a
string, then dereference it as an int and go happily along my way
without knowing that the value will be meaningless.

Of course, in C#, this will throw a runtime exception. But it's not
the "C# way" to do it. If you want to store user data, either subclass
the widget and give it a proper name/type, or store a separate
(strongly-typed) dictionary. It all depends on the exact application,
but either way, just throwing data into a grab bag is ignoring the
type system that makes C# awesome.

Anyway, sorry to budge in, just my 2 cents.

On Thu, Nov 26, 2009 at 1:37 PM, Chuck Esterbrook
<chuck.esterbrook at gmail.com> wrote:
> On Thu, Nov 26, 2009 at 9:37 AM, Christian Hoff <christian_hoff at gmx.net> wrote:
>> Hey guys,
>>
>> GLib.Object.Data is deprecated according to the docs, but it is not marked
>> obsolete in the code for whatever reason. Maybe this decision has been
>> reverted and the docs have not been updated yet.
>>
>> In any case, that means that it won't be removed in Gtk# 3.0. Any thoughts
>> on this issue, Mike?
>>
>> Christian
>
> So I did a:
>
> svn co svn://anonsvn.mono-project.com/source/trunk/gtk-sharp
>
> And checked out the code:
>
>        public Hashtable Data {
>                get {
>                        if (data == null)
>                                data = new Hashtable ();
>                        return data;
>                }
>        }
>
> There are no attributes on it and this implementation is a typical
> approach. I might prefer a Dictionary<of String, Object> return type,
> but no worries.
>
> Thanks for pointing this out.
>
> -Chuck
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>


More information about the Gtk-sharp-list mailing list