[Glade-devel] Some ideas on window's specific code.



On Sun, 2003-08-17 at 21:44, Archit Baweja wrote:
Hi

I noticed that in some source files that Joaquin has been using some "goto" 
statements to make glade3 compilable on windows platform. (lblError is a goto
tag I saw in there). Don't you think it is better to use preprocessor flags
and #ifdef's rather than lblError? or is that "goto" for something else besides
window's specific code. We all know "goto" is not all that an encouraged
programming practice.


I have not looked deeply in these changes but I don't think that these
'goto' are windows specific... with coding style we enter in one of
those religious issues, but personally I like the use of gotos for error
handling.
At school they teach you that gotos are evil because they can lead you
to spaghetti code if you use them to execute some kind of subroutine
(basic anyone?), but for error handling I find them very elegant and
clean: they allow you to keep all the error handling path concentrated
in one place without getting in your way when you're trying to
understand the logic of the code that is execueted when everithing is
alright.

I mean:

gboolean
my_function ()
{
        gboolean ret = FALSE;
        ...
        mystuff = malloc (...)
        ...
        if (something_wrong)
                goto error;

        /*  main code path */
        ...
        ret = TRUE;

error:
        free (mystuff);
        return ret;
}

If it was me, every function should have only _one_ 'return' statement
and use gotos on error handling, in order to free all the allocated
resources... [Of course the functions which don't allocate anything and
that need to make some short-circuit tests and return are an exception
to this rule]

ciao
        paolo








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