From owner-cvs-src@FreeBSD.ORG Fri Feb 11 13:49:14 2005 Return-Path: Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 082C916A4CE; Fri, 11 Feb 2005 13:49:14 +0000 (GMT) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6172B43D1D; Fri, 11 Feb 2005 13:49:13 +0000 (GMT) (envelope-from bde@zeta.org.au) Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86])j1BDn8A6012559; Sat, 12 Feb 2005 00:49:08 +1100 Received: from katana.zip.com.au (katana.zip.com.au [61.8.7.246]) j1BDn4Tv002307; Sat, 12 Feb 2005 00:49:06 +1100 Date: Sat, 12 Feb 2005 00:49:03 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Poul-Henning Kamp In-Reply-To: <10137.1108121831@critter.freebsd.dk> Message-ID: <20050212001652.L32719@delplex.bde.org> References: <10137.1108121831@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: rizzo@icir.org cc: src-committers@freebsd.org cc: cvs-all@freebsd.org cc: "M. Warner Losh" cc: cvs-src@freebsd.org Subject: Re: cvs commit: src/sys/dev/ed if_ed.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Feb 2005 13:49:14 -0000 On Fri, 11 Feb 2005, Poul-Henning Kamp wrote: > In message <20050211220212.A32327@delplex.bde.org>, Bruce Evans writes: > > >> : while (complicated-expr) > >> : ; > > Look, programming is the art of expressing intent as best as > possible. The single semicolon variant is very clear from > a compiler point of view, but it is not clear from a human > point of view. No, both look like random punctuation from a human point of view, but from a C programmer point of view the single semicolon is a normal idiom while "continue;", while simple, takes a little longer to understand since it is not normal for leaving the end of a loop. "continue; is for leaving the middle of a loop. > I always use the continue variant because I feel it expresses > intent better for two reasons: > > The visual impact of a word is much bigger than that of a single > lightweight character. > > Writing "continue" dispells any doubt if I did it intentionally. I disagree, and always use a single semicolon on a line by itself to make it clear that I did it intentionally. K&R2 seems to always use a single semicolon. The first instance of a loop with a null statement in K&R2 seems to be on page 48 for an implementation of strcat(): %%% ... while ((s[i++] = t[j++]) != '\0') /* copy */ ; %%% All this is idiomatic for C progammers. If you aren't a C programmer, then the null statement is the easiest thing in it to understand. FreeBSD's implementation of strcat() is essentially the same, but uses the canonical idiom for copying strings (pointers instead of arrays) and has style bugs on every line: %%% for (; *s; ++s); while ((*s++ = *append++) != 0); return(save); %%% (The style bugs in this are 2 semicolons not on a separate line, 0 instead of '\0', and no space before the silly parentheses around the return value.) Some other examples in K&R2: p60 "while (...)\n\t; /* ... */" p61 "for (...) /* ... */\n\t;" p71 "for (...) /* ... */\n\t;" p78 "while (...)\n\t;" I stopped looking at p80 without finding any examples with "continue;" or "/* nothing */ ;". Guess which style is used in one-true-awk. Bruce