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

Re: Python or Perl for a Debian maintainance project?



On Tuesday 17 Feb 2004 4:58 pm, Andrew Suffield wrote:

> > void shoe()
> > {
> >   /* Do some complicated stuff */
> >   if (foo == NULL)
> > 	goto cleanup;
> >   /* Continue complicated stuff */
> >   if (bar == 3)
> > 	goto cleanup;
> >
> > cleanup:
> >   /* Cleanup */
> > }
>
> Good grief, that's *terrible* C. Don't do things like that. The
> problem here is not a lack of exceptions, it's just bad code. As
> usual.

As usual? OK.

That is an often used convention, used by many substantial pieces of C code 
that you are running on your system right now. Admittedly it is much more 
often used in system level situations than application code. It can be argued 
that much C is *terrible*. That's why it's C.

> Here's how you should do that:

<snip>

> static bool
> process_foo(struct foo *foo)
> {
>   if (!check_foo(foo))
>     {
>       /* report and die */
>     }
>
>   /* process it */
> }
>
> (Most uses of goto should be replaced with function calls; the rest
> should be replaced with block-structure statements)

Unfortunately this doesn't necessarily work if you need to do work 
(allocations, side effects) in between checking foo and bar.

> Exceptions should only be used for exceptional circumstances, and even
> then think twice. The single thing for which they are useful is to
> throw an error a long way to an unknown handler, which may or may not
> understand the error. This is not often useful - library APIs are the
> most notable case. Using exceptions in any other circumstances is
> usually a really bad idea.

I beg to differ.



Reply to: