Re: Structures thought question



On Sun, 2008-11-16 at 13:51 +1100, Robert Collins wrote:
> On Sat, 2008-11-15 at 21:28 -0500, Havoc Pennington wrote:
> > 
> > > void gdk_region_union (GdkRegion       *source1,
> > >                       const GdkRegion *source2);
> > 
> > I would expect "inout source1" as "this" and "in source2"
> > 
> > source1.union(source2);
> 
> I would have expected a union operation to be a three parameter:
> result = source1.union(source2);
> 
> (like +, - and other operators).

Not completely on-topic, but easier for me to answer then some other
questions :-)

Although Xlib regions operations are 3 parameter functions, when I
adapted the code for GTK+ I went with the paradigm of a method call that
modifies the instance for a number of reasons:

 - No need to worry about which of the 8 permutations of three
   parameters you are using. Especially important when the operation
   isn't symmetric ... like gdk_region_subtract().
  
 - Any time you have a 3-parameter operation, when reading or writing
   the code it's hard to avoid worrying about whether using one of
   the sources as the destination is OK or there is some implementation
   limitation or bug.

 - For an allocated structure like GdkRegion, using a three parameter
   operation to do c = a op b is awkward anyways since you have to
   create C ahead of time.

 - The method better represents what is going on internally ...
   it is in fact cheaper to in many cases to keep on mutating a single
   region then to copy it to a new region.

I think it has worked out very well.

- Owen




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