Zitat von "Sven Neumann" <s...@gimp.org>:

> On Wed, 2010-04-21 at 12:33 +0200, Oliver Bandel wrote:
>
>> Example:
>>
>>
>> ==============================================
>> /*****************************************************************************/
>> /*  public functions
>> ********************************************************/
>>
>> GimpContext *
>> gimp_context_new (Gimp        *gimp,
>>                    const gchar *name,
>>                    GimpContext *template)
>> {
>>    GimpContext *context;
>>
>>    g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
>>    g_return_val_if_fail (name != NULL, NULL);
>>    g_return_val_if_fail (! template || GIMP_IS_CONTEXT (template), NULL);
>>
>>    context = g_object_new (GIMP_TYPE_CONTEXT,
>>                            "name", name,
>>                            "gimp", gimp,
>>                            NULL);
>>
>>    if (template)
>>      {
>>        context->defined_props = template->defined_props;
>>
>>        gimp_context_copy_properties (template, context,
>>                                      GIMP_CONTEXT_ALL_PROPS_MASK);
>>      }
>>
>>    return context;
>> }
>> ==============================================
>>
>> The test
>>    if( template )
>> makes only sense, if you can be sure that uninitialzed values
>> will definitely be NULL.
>
> "template" isn't uninitialized here. It is a parameter passed to
> gimp_context_new() and it may either be NULL or a pointer to a valid
> GimpContext object. This is even checked right at the beginning of the
> function.


Yes, you are right.

But "context" is not initialized at definition.

It get's it's value later on.

When changing code, forgetting to set a value later might bring problems.

    GimpContext *context = NULL;

Right after beginning of the function is, what I mean.

In this small function one can oversee what's going on.
In larger functions it's not always obviously, and such
semmeingly non-necessities can help in shrinking down debugging
time from weeks to minutes, especially in big projects.

I prefer programming in paranoid mode ;-)
It helps, if the coffee is empty with early core dumps... ;-)

When I see the huge database and complexity of gimp, I prefer such
a way even more. :)

When I look at scheme.c, it has some thousands lines and some  
functions are many screens long... DEK would say: a function should  
not be larger than one page or screen size.... I agree in that point.

Ciao,
    Oliver

_______________________________________________
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

Reply via email to