Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site lsuc.UUCP Path: utzoo!lsuc!msb From: msb@lsuc.UUCP (Mark Brader) Newsgroups: net.lang.c Subject: Re: C Indentation Survey Results (long...) Message-ID: <626@lsuc.UUCP> Date: Sun, 28-Apr-85 00:13:40 EDT Article-I.D.: lsuc.626 Posted: Sun Apr 28 00:13:40 1985 Date-Received: Sun, 28-Apr-85 03:08:10 EDT References: <9930@brl-tgr.ARPA> <381@busch.UUCP> <5497@utzoo.UUCP> <350@gumby.UUCP> <5521@utzoo.UUCP> <904@ucbtopaz.CC.Berkeley.ARPA> Reply-To: msb@lsuc.UUCP (Mark Brader) Organization: Law Society of Upper Canada, Toronto Lines: 53 Summary: Prettyprinters lose information. Make your code look like co-workers'. There've been a couple of suggestions lately like this one from mwm@ucbtopaz.UUCP (Praiser of Bob (!)): > Whenever I read/write code, I prefer it in a format that I find easy to > read. The AI community found the solution to the problem of different > code formatting styles two (or more?) decades ago: customizable pretty > printers (beautifiers, if you must). You read your code into the editor, > notice that the format is "ugly", and tell the editor to format it the > way you like it. The next person to come along goes through the same > process. The trouble with this is that prettyprinters don't know what you know. Consider these two examples: if(isdigit(c)) A(); else if(isupper(c)) B(); else if(islower(c)) C(); else D(); if (snowing) A(); else if (political) B(); else if (Saturday) C(); else D(); Of course, A(), B(), etc. stand for several lines of code in each case. The first one is a case-type construct consisting of multiple tests of the same variable. The second one, on the other hand, consists of a series of completely independent tests and bears only a superficial resemblance to the first. The second one might as well have been written: if (!snowing) if (!political) if (!Saturday) D(); else C(); else B(); else A(); ... except that this is less readable in most cases. The distinction between the two constructs is often expressed by writing them like this: if (isdigit(c)) if (snowing) A(); A(); else if (isupper(c)) else B(); if (political) else if (islower(c)) B(); C(); else else if (Saturday) D(); C(); else D(); Now show me a prettyprinter that can tell these apart. Remember, it has to be able to start from the compressed form I gave originally! Then there are things like putting comments to the right of code or above it, and whether */ /* indicates two comments or end-of-line inside a comment, and carefully aligned lines to illustrate parallel operations.... prettyprinting just doesn't do it all. Really, the only solution is to make your code look like that of the people you work with.... or start your own company and make it a trade secret. Mark Brader