From owner-freebsd-hackers Tue May 28 04:41:42 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id EAA19857 for hackers-outgoing; Tue, 28 May 1996 04:41:42 -0700 (PDT) Received: from eac.iafrica.com (slipper119229.iafrica.com [196.7.119.229]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id EAA19851 for ; Tue, 28 May 1996 04:41:33 -0700 (PDT) Received: (from rnordier@localhost) by eac.iafrica.com (8.6.12/8.6.12) id NAA00234; Tue, 28 May 1996 13:37:55 +0200 From: Robert Nordier Message-Id: <199605281137.NAA00234@eac.iafrica.com> Subject: Re: Indentation styles To: grog@lemis.de (Greg Lehey) Date: Tue, 28 May 1996 13:37:53 +0200 (SAT) Cc: hackers@FreeBSD.org In-Reply-To: <199605280901.LAA23008@allegro.lemis.de> from "Greg Lehey" at May 28, 96 11:01:19 am X-Mailer: ELM [version 2.4 PL24 ME8a] Content-Type: text Sender: owner-hackers@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk Greg Lehey wrote: > > OK, I know source code indentation styles are a hot button, but I > think I need to press it anyway. > > First, a question: is there a recommended FreeBSD indentation style? > If not, I think there should be. > > Now, my problem: I frequently modify other people's code, which > sometimes causes me problems in reading, simply because the > indentation varies so much from the indentation that my tools and I > use. Frequently, I just give up and run the whole source through > indent(1). The resulting modifications work (usually), but it's > difficult to pass them back to the original author as diffs. > > Therefore, my suggestion: if FreeBSD doesn't have a canonical > indentation style, it should get one. The style should be > reproducible with indent(1). (For those of you who don't know, > indent(1) has a plethora of flags which can create just about any > indentation style you like). That way, individuals can code in styles > in which they feel comfortable, but when they submit code, it's in the > canonical form. It would be an advantage, of course, to choose a > canonical form which corresponds to the tastes of the majority. > > If there is already a recommended FreeBSD indentation style, can it be > reliably produced with indent(1)? If not, what do people think about > modifying it to a (closely similar) form which can be created with > indent(1)? > > If there isn't a recommended FreeBSD indentation style, do you agree > that there should be one? What should it be like? > > Finally, a restriction. Indent style can, in some cases, influence > coding style: for example, if you choose an indent of 8 and indent > braces 8 characters and the contents of a block another 8 spaces, > you'll soon run out of margins. Even if you only indent a single 8 > characters, you'll end up writing different code from people running > smaller indents. Does this matter? > > Thoughts? Flames? Yuk! I think 'indent' should be hardwired to output to '/usr/tmp'. 'indent' is primarily useful as a tool to make sense out of other people's code. So, if their style differs from yours, indent can be used to produce a rough translation, which may be useful to promote understanding. But 'indent' needs to be used a logical tool, for personal use, not as something to chop and stretch code into rigid conformance with any One True Way of doing things. Some people take immense care in the formatting of their code, however eccentric the layout may appear to those used to a different style. To stomp all over this with 'indent' would be decidedly a Bad Thing. Unless you format your code with indent in mind, indent is pretty much guaranteed to make a mess of it. (Well, of the finer points, anyway.) Any particular patch or modification is likely to comprise far less code than the original source. In these circumstances, it is surely better to match the style of the original. There is an awful lot of code out there, in various indentation styles. To go in and re-indent the lot of it is going to create massive change, problems, and uncertainty. (And probably will turn up a few bugs in indent, which may be detected only when program behavior suddenly changes.) If the required indentation style is applicable only to new code, the legacy code is always going to be in the majority. So there will not be the desired overall conformity. Indentation styles raise strong feelings. I was looking at some stuff the other day in which the author specifically prohibits reformatting the source as part of the conditions for free use and distribution. (I think it was part of Minix.) The Bell Labs 'Indian Hill Style Guide' is generally regarded as the most authoritative of such guides, by those who take these matters seriously. It has this to say about 'indent' and friends: This committee recommends that programmers not rely on automatic beautifiers for the following reasons. First, the main person who benefits from good program style is the programmer himself. This is especially true in the early design of handwritten algorithms or pseudo-code. Automatic beautifiers can only be applied to complete, syntactically correct programs and hence are not available when the need for attention to white space and indentation is greatest. It is also felt that programmers can do a better job of making clear the complete visual layout of a function or file, with the normal attention to detail of a careful program- mer53. Sloppy programmers should learn to be careful programmers instead of relying on a beautifier to make their code readable. Finally, it is felt that since beautifiers are non-trivial programs that must parse the source, the burden of maintaining them in the face of the continuing evolution of C is not worth the bene- fits gained by such a program. _________________________ 53. In other words, some of the visual layout is dictated by intent rather than syntax. Beautifiers cannot read minds. (For those influenced by Classical allusions, the Greek legend of Procrustes is also very apposite.) I think Greg's concern in valid, but this is one of Nature's Insoluble Problems. Let's have some sanity, please! -- Robert Nordier