Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.std.c Subject: Re: comment style Message-ID: <17968:Jan804:38:1591@kramden.acf.nyu.edu> Date: 8 Jan 91 04:38:15 GMT References: <613@caslon.cs.arizona.edu> <1050:Jan701:40:4791@kramden.acf.nyu.edu> <616@caslon.cs.arizona.edu> Organization: IR Lines: 45 In article <616@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes: > In article <1050:Jan701:40:4791@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: > |1. [ x/*p can be evaluated as a reasonable expression ] > This is a reasonable argument against why /* is a poor choice as a comment > starter. However, the time to point this out was 20 years ago, when Dennis > Ritchie was designing C. I'm not saying that we should rush to change anything. It's just a point to remember for the future: // comments would help avoid a common error. Similarly, I don't think we should rush to change strcmp() to strdiff(), but we should remember that the latter would help avoid a common error. > |2. // is shorter and easier to type than /* */. > |3. // is more visually striking than /* ... */. > These are matters of personal taste. No. #2 is an objective fact and #3 is a widely accepted principle of visual design: parallel lines are striking. Read Tufte's books. > |4. It is always obvious, to both human eye and mechanical parser, where > |a // comment ends (viz., the end of the line). It is not so trivial to > |locate the next */. > My editor has a 'search for text' function. Doesn't yours? My eyes don't have a ``search for text'' function, and it takes just a bit longer for the computer to recognize a two-character sequence than to recognize a one-character sequence. > |5. Placing // at the beginning of several lines is guaranteed to comment > |out the entire section. There is no easily applied rule for /*...*/. > Comments are not for hiding code from the compiler. But the fact is that people want to use comments to hide code (and text). #if/#endif is not safe for hiding code and simply doesn't work right for hiding text. > However, as > another post points out, // comments can have there own pitfalls when the line > ends with a '\'. No, not when they're done correctly. When you have end-of-line comments there's no need for continuation characters. *All* characters are ignored between // and newline inclusive. ---Dan