FYI, the new kernel newbie column is out
Robert P. J. Day
rpjday-L09J2beyid0N/H6P543EQg at public.gmane.org
Wed Jul 8 16:15:49 UTC 2009
On Wed, 8 Jul 2009, D. Hugh Redelmeier wrote:
> | From: Robert P. J. Day <rpjday-L09J2beyid0N/H6P543EQg at public.gmane.org>
>
> | http://cli.gs/0LUN27
>
> int err;
> /* registration takes a pointer and a name */
> err = register_this(ptr1, "skull");
> if (err) goto fail_this;
> err = register_that(ptr2, "skull");
> if (err) goto fail_that;
> err = register_those(ptr3, "skull");
> if (err) goto fail_those;
> return 0; /* success */
>
> fail_those: unregister_that(ptr2, "skull");
> fail_that: unregister_this(ptr1, "skull");
> fail_this: return err; /* propagate the error */
>
> I think that the code would be clearer if written this way:
>
> int err;
> /* registration takes a pointer and a name */
> err = register_this(ptr1, "skull");
> if (!err) {
> err = register_that(ptr2, "skull");
> if (!err) {
> err = register_those(ptr3, "skull");
> if (!err)
> return 0; /* success */
>
> unregister_that(ptr2, "skull");
> }
> unregister_this(ptr1, "skull");
> }
> return err; /* propagate the error */
i disagree, and there's actually a tradition in modules to use the
"goto" to avoid precisely that cascading indentation. in any event, i
was stealing straight out of the LDD3 book so i wanted to stick with
their content to allow readers to cross-reference and not have to
mentally translate.
but even if that last part weren't an issue, i'd probably still go
with the original code. it seems to be the standard and i find it
more readable. but that's just me.
rday
--
========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA
Linux Consulting, Training and Annoying Kernel Pedantry.
Web page: http://crashcourse.ca
Linked In: http://www.linkedin.com/in/rpjday
Twitter: http://twitter.com/rpjday
========================================================================
--
The Toronto Linux Users Group. Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists
More information about the Legacy
mailing list