GNOME Bugzilla – Bug 624005
CompareFunc poorly documented and confusing
Last modified: 2012-08-06 01:32:35 UTC
I struggled a bit trying to sort a Gee.List<int> in descending order. CompareFunc is very un-vala-like because it takes two void pointers as parameters: [http://www.valadoc.org/glib-2.0/GLib.CompareFunc.html] public int CompareFunc (void* a, void* b) The documentation needs to say what the pointers actually point to. Your typical C programmers will assume that all you need to do is cast and dereference, but that will cause a segfault! After printing the raw pointer values I saw that they in fact hold the real integer values directly: stdout.printf("a=%u b=%u\n", a, b); //a=0x2 b=0x1 Using pointers to store non-pointer values! In my estimation this will be very unexpected to 99% of the programmers using Vala and Gee. Could generics be used instead?
Please add dependency on bug #592993. It is vala limitation not ours.
If feature #592993 is going to take a long time I'd suggest improving the documentation too.
Isn't it generated from GLib docs?
Yes, its autogenerated. Still, I agree that a helpful example would not be so bad. I remember struggling with this method myself for many hours before getting my code to work. :)
Created attachment 219533 [details] [review] Add missing CompareDataFunc type arguments
I wonder if something like: enum Ordering { LT = -1, EQ = 0, GT = 1 } would not be better as result.
(In reply to comment #6) > I wonder if something like: > > enum Ordering { > LT = -1, EQ = 0, GT = 1 > } > > would not be better as result. CompareDataFunc is in glib, not libgee, so obviously that would have to change. More importantly, though, you lose compatibility with existing comparison functions.
Review of attachment 219533 [details] [review]: Looks good. > CompareDataFunc is in glib, not libgee, so obviously that would have to change. > More importantly, though, you lose compatibility with existing comparison > functions. Ups. My fault.
commit b3768e475a7d71af17daeb66b9151d258c4a687c Author: Evan Nemerson <evan@coeus-group.com> Date: Mon Jul 23 13:32:58 2012 -0700 Add missing CompareDataFunc type arguments, fixes bug 624005