Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Jun 2003 21:29:15 -0400
From:      Garance A Drosihn <drosih@rpi.edu>
To:        "Poul-Henning Kamp" <phk@phk.freebsd.dk>, "Sam Leffler" <sam@errno.com>
Cc:        cvs-all@FreeBSD.org
Subject:   Re: cvs commit: src/sys/vm vm_mmap.c
Message-ID:  <p0521063cbb1c0360e6bb@[128.113.24.47]>
In-Reply-To: <1197.1056217385@critter.freebsd.dk>
References:  <1197.1056217385@critter.freebsd.dk>

next in thread | previous in thread | raw e-mail | index | archive | help
At 7:43 PM +0200 6/21/03, Poul-Henning Kamp wrote:
>  >>   Log:
>  >>   Use a do {...} while (0); and a couple of breaks to reduce
>  >>   the level of indentation a bit.
>>>  
>>>    Revision  Changes    Path
>>>    1.161     +80 -78    src/sys/vm/vm_mmap.c
>  >> http://cvsweb.FreeBSD.org/src/sys/vm/vm_mmap.c.diff?r1=1.160&r2=1.161
>>
>>I find this change truly repulsive and gratuitous.
>
>It is a precusor to moving devices out of vnodes.  In order to
>get the patch which _does_ something to be manageable, I will
>sort out some minor issues first, this is one of them.
>
>If your complaint is about the use of do { ... break; ... break; }
>while (0); then launch an campaign to have it banned in style 9.
>
>IMO it is superior to goto, and ever deepening if-else constructs.

For this specific example, I don't see that it really buys you
all that much.  However, I would say that there are times that
the 'do { ... break; ... break; } while (0);'
strategy can be much easier to read than ever-deepening if-else's.
I would not be happy to see it banned in style(9).

When I use it, I do tend to put a comment on the either the
first or the file line, eg:
	do {		/* just a target for 'break's */
	} while (0);	/* just a target for 'break's */

This is just my own opinion, of course.  I'm not going to get all
wild-eyed and pound the table over it.  The other tactic I use is:
	if (...) {
		if (other)
			goto skipstuff;
  		if (yetmore)
			goto skipstuff;
		...stuff...
	skipstuff:
		alwaydo()
	}
which works about the same when it comes to indent-levels.

-- 
Garance Alistair Drosehn            =   gad@gilead.netel.rpi.edu
Senior Systems Programmer           or  gad@freebsd.org
Rensselaer Polytechnic Institute    or  drosih@rpi.edu



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p0521063cbb1c0360e6bb>