Re: GnomeProgram in libgnome



On 9 Oct 2001, Havoc Pennington wrote:

>
> James Henstridge <james daa com au> writes:
> > Does anyone have an idea of what should be happening here?
>
> <insert "init functions are evil" commentary>

I am not suggesting that a program would want to call gnome_program_init()
more than once, but that doing so will create multiple GnomeProgram
objects, which shouldn't happen if it is meant to be a singleton.

Also, the functions _preinit, _parse_args and _postinit are provided in
the case where you may wish to do something between these parts of the
init process.

However, if a program decides to use these functions, the only way they
can create the GnomeProgram instance is with g_object_new(), and that
instance never gets assigned to the global_program variable, so will never
be returned by gnome_program_get().  This may cause problems later on.

>
> If we have an init function that takes arguments, then it has to be
> called once and only once, which is of course broken, but less broken
> than allowing it to be called twice.

I don't suggest calling it twice is a good idea.  This was an example of
where treating GnomeProgram as a singleton breaks down.

>
> i.e. we should only call the function once, and it should create a
> global singleton GnomeProgram at that time.
>
> But init functions should only do things that really, fundamentally,
> can be done only once; such as connect to the X display. All other
> initialization should simply be done lazily/automatically on-demand.

Argument parsing is the big one that needs to be done cooperatively in
order to be done right.  You really need to know of all the acceptable
options in order to parse the arguments.  For example:
  --foo --display bar:0.0

You need to know if --foo takes an argument to decide whether the
--display argument was given.

>
> Ideally we could kill gnome_program_init() and just have a
> gnome_program_get(), in other words.

Having an easy way for libraries to cooperate in argument parsing is a
good reason to keep gnome_program_init().

James.

-- 
Email: james daa com au
WWW:   http://www.daa.com.au/~james/






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