Path: utzoo!mnetor!uunet!oddjob!ncar!ames!necntc!ima!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.misc Subject: Re: Style rules for C shops Message-ID: <20663@think.UUCP> Date: 11 May 88 03:58:11 GMT References: <12120@santra.UUCP> <1962@bgsuvax.UUCP> <12567@santra.UUCP> <4043@killer.UUCP> Sender: usenet@think.UUCP Reply-To: barmar@kulla.think.com.UUCP (Barry Margolin) Distribution: comp.lang.misc,comp.lang.c Organization: Thinking Machines Corporation, Cambridge, MA Lines: 40 In article <4043@killer.UUCP> loci@killer.UUCP (loci!clb) writes: >In article <12567@santra.UUCP>, news@santra.UUCP (news) writes: >> That sounds like a nice solution, except that there are certain styles >> that a beautifier cannot produce. For instance, how do you make it >> produce meaningful variable names? How do you make sure the program uses >> constants (defines) when appropriate? What do you do with too lengthy >> procedures? > The obvious solution to "how do ...": write a pre-processor > to do exactly what you want. If editors can be written and > compilers can be written, then this is just another application > package. With "yacc" and a "lex", it's easy to get started. I seriously doubt that we have anything close to the technology to do what you suggest. The point of the >> comment is that some of the important "style" rules have to do with understandability of programs. Do you really think that someone could write a lex/yacc program that would figure out how to rename single-character variable names to something that makes more sense to a human reader? These features are not just about static program format, but about how well the structure of the program reflects the problem being solved. It takes something with intelligence to do this. AI programs like the Programmer's Apprentice might be able to help in this regard, but they still rely on the programmer to do most of the work. But I think it would take a program smarter than we know how to build to determine whether the "1" in variable1 = variable1 + 1; should be replaced with a #define'd constant or not. It depends on just what the "1" represents in the context of the program; if we're just incrementing variable1 it should stay as it is (although perhaps a style improver might turn this into "variable1++;"), but if the "1" represents something more abstract it should be given a meaningful name. Barry Margolin Thinking Machines Corp. barmar@think.com uunet!think!barmar