Re: Default values for properties



Tim Janik <timj gtk org> writes:

> g_object_new() will only set G_PARAM_CONSTRUCT* proeprties for you, but yes,
> it will set those with default values if not upplied by the user.
> the reason for this is two fold, basically we do what a c++ constructor
> would do if you supplied all of its arguments with default values, but,
> probably more interesting, i took that behaviour over from 1.2.
> 
> a flag as you suggest would only affect CONSTRUCT properties, however
> that will cause us ending up with four variants thereof:
> 
> G_PARAM_CONSTRUCT		/* supply always for constructor */
> G_PARAM_CONSTRUCT_ONLY	        /* supply if and only if we're constructing */
> G_PARAM_CONSTRUCT_EXPLICIT	/* supply with constructor when user-provided */   
> G_PARAM_CONSTRUCT_ONLY_EXPLICIT /* supply if and only if (constructing &&
>                                                           user-provided) */
> 
> i'm not sure that thse additional flags aren't more intriguable than
> benefitting.

Huch, why so complicated ?

  G_PARAM_CONSTRUCT             /* pass this property to the constructor */
  G_PARAM_CONSTRUCT_ONLY        /* this property is only allowed at construction
                                 * time; you may not modify it later on. */
  G_PARAM_CONSTRUCT_NODEFAULT   /* this property has no reasonable default
                                 * value */ 

> OTOH, since we now have GObjectClass.constructor, i'm not sure
> we still have to default-supply all construct properties at construction
> time. but before i change that, i'd like to know why you have to distinguish
> "user specified construct property with default value" from
> "construct property gets default value, but wasn't user-specified".

Well, IMHO not supplying any default values at construction time won't hurt
at all; all of these properties there is absolutely no need to do this since
you can also set the default value in the object's instance_init function.

However, if you supply any default values at construction time, you won't be
able to find out whether a property has been user-supplied or not.

There are basically two problems with this:

(a) there are properties which don't have any reasonable default values
    or whose default values depend on other properties.

(b) it should be allowed to specify construction properties multiple times
    (oh, I forgot that I wanted to report this as a bug!)

Basically, I see construction properties more as arguments which you use
at object construction time to tell the object how you look, feel and behave
than as real "properties".

Currently, g_object_new() doesn't allow me to do (with both "module" and
"module_info" being G_CONSTRUCT_ONLY and write-only)

        g_object_new (GNOME_TYPE_PROGRAM,
                      "module", "libgnomeui",
                      "module", "libbonoboui",
                      "module_info", foo_module_info,
                      NULL);

or, for instance in a scripting language

        (g-object-new 'gnome-type-icon-selector
                '((icon-path . "/gnome/head/INSTALL/share/icons")
                  (icon-path . "/gnome/unstable/INSTALL/share/icons")
                  (icon-path . "/gnome/release/INSTALL/share/icons")))

Btw. I'm not so familar with C++, but I don't think it's required to specify
default values for all all arguments ?    

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)




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