Re: Sinkability considered harmful

On Tue, 3 Jan 2006, Federico Mena Quintero wrote:

Sinkability considered harmful

The "floating" flag was introduced in GtkObject to:

	1. keep this convention

	2. make things easier for language bindings.

this is not quite right. the floating flag is of no use to langauge bindings,
if it affects them, it makes things harder for LBs.

the idea for the floating flag was born to maintain historic and
non-ref-counting-aware code, yes. however, it's use has evolved since.
at this point, there really is only one reason to have a floating flag
(and the reference documentation states that):

  1. "The main motivation for providing floating references is C convenience"

so asid for maintaining API compatibility, there is no technical need for
a floating flag.


Let's not have a floating flag in GObject, as it promotes bad API

Let's keep GtkObject and GtkWidget as they are, as a historical
artifact, and just let language bindings deal with them as they do

APIs which want to reinvent float/sink do so at their own peril.

one can maintain your claim from a purely technical perspective.
however, it is not very helpfull for everyday coding in C. let's
investigate what the floating flag buys your in every day C code.

with a floating flag, you write:

  some_container_add (container, create_a_floating_object());

without a floating flag, you'll have to unref. in order to unref,
you need the reference to the newly created object twice, thus
you're forced to use a variable. in portable C, variables may not
be declared in code inline, but have to go into their own declaration
section at the start of a code block.
if additionally you don't accept inline assignments in your code (e.g.
Gtk+ or Gimp coding style) you need an extra line for the variable
assignment. thus you end up with:

  MyObject *object;	/* move to declaration section */

  object = create_a_floating_object();
  some_container_add (container, object);
  my_object_unref (object);

so for a pretty common every day task, what has been a 1 liner before,
becomes 4 lines, one of which even needs to be moved into a possibly
distant code section.
one could argue that 75% of this code distracts from the task at hand,
which is adding a new obejct to a container, that gets pretty bad
ratings in terms of code readability and maintainability.

so, the additional overhead required in portable C was/is simply regarded
too big to abandon the floating flag. as a proof, take a look at all the
cases where the floating flag functionality has been duplicated, or where
developers are considering to duplicate it. GtkObject, GParamSpec and
GClosure are just where this was considered useful in glib & gtk+.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]