Von: "Martin Pitt" <[email protected]>: >> 1. Some functions return useless "success" boolean: for example >> [success, contents, etag_out] = GFile.load_contents(). When C >> g_file_load_contents returns false, it also sets GError, so in Gjs it's >> either true or the function has thrown exception. > > Note that many other functions with that style don't throw a GError. > In PyGObject we have overrides for many of them to filter out the bool > and only return the (out) arguments if the return value is True. Look > for "strip_boolean_result" in > http://git.gnome.org/browse/pygobject/tree/gi/overrides/Gtk.py
We use a similar approach in the Perl bindings: <http://git.gnome.org/browse/perl-Glib-Object-Introspection/tree/lib/Glib/Object/Introspection.pm#n48>, <http://git.gnome.org/browse/perl-Gtk3/tree/lib/Gtk3.pm#n49>. When functions with a "success" boolean and out arguments don't throw an exception, you can still get rid of the boolean if your language supports a variable number of return values. You simply return nothing then in the case the boolean is false. But note that you cannot use a heuristic like "has boolean return value and out arguments" to decide whether to apply this approach: gtk_tree_selection_get_selected is a counter example, <http://developer.gnome.org/gtk3/3.2/GtkTreeSelection.html#gtk-tree-selection-get-selected>. I also think an annotation for boolean return values that states "this is a sentinel for whether the out args have been set" would be useful. It would make it possible for bindings to share this information. _______________________________________________ desktop-devel-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/desktop-devel-list
