From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Mon, 22 Jan 2001 16:09:41 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Mon, 22 Jan 2001 16:09:31 -0500 Received: from fluent1.pyramid.net ([206.100.220.212]:26163 "EHLO fluent1.pyramid.net") by vger.kernel.org with ESMTP id ; Mon, 22 Jan 2001 16:09:23 -0500 Message-Id: <4.3.2.7.2.20010122130852.00b92a80@mail.fluent-access.com> X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Mon, 22 Jan 2001 13:09:07 -0800 To: linux-kernel@vger.kernel.org From: Stephen Satchell Subject: RE: [OT?] Coding Style Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org At 11:04 AM 1/22/01 -0500, you wrote: >WRONG!!! > >Not documenting your code is not a sign of good coding, but rather shows >arrogance, laziness and contempt for "those who would dare tamper with your >code after you've written it". Document and comment your code thoroughly. >Do it as you go along. I was also taught to comment nearly every line - as >part of the coding style used by a large, international company I worked for >several years ago. It brings the logic of the programmer into focus and >makes code maintenance a whole lot easier. It also helps one to remember >the logic of your own code when you revisit it a year or more hence. Oh, those who refuse to study history are doomed to repeat it. The COBOL language was created specifically to reduce the amount of commenting necessary in a program, because the English-like sentence structure could be read and understood by humans. The FORTRAN language was created so that math types could "talk" in a language more familiar to them, letting the computer take care of the details about how to perform the specified task step-by-step. One goal of language designers is to REMOVE the need for comments. With a good fourth-generation or fifth-generation language, the need for comments diminishes to a detailed description of the data sets and any highly unusual operations or transforms on the data. I've even gone so far as to "invent" my own languages, and the parsers to go with them, to reduce the need to comment by making the code easy for humans to read. Not only are such systems easier to debug (with good language design) but are highly maintainable and usually not all that difficult to extend when necessary. Remember, the line-by-line commenting requirement was mandatory in assembler programming, because the nature of assembler made you outline each step by tiring step. When I worked for Rockwell, I was granted a partial wavier when I showed them my assembler-language commenting style: pseudo-code at the top of each block of assembler code. Blindly applying the rule to second-generation and later languages is just sloppy management, usually by people who don't understand coding. (And yes, that includes some professors of computer science I have known.) Comments do NOT make code maintenance easier. Too many comments obscure what is really going on. Linus' style actually increases the maintainability of the code, because if the code doesn't accurately show how it implements the goal specified in the block comment, the coder hasn't done his/her job. Want to improve the maintainability of C code? Consider the following: 1) Keep functional parts small. If the code won't fit in a hundred lines or so of code, then you haven't factored the problem well enough. Functional parts != functions. A program with thousands of well-encapsulated function parts strung together into a single function is easier to maintain than a "well-factored" program with its parts spread all over hell. Diagnostic programmers have learned the hard way that factoring a program can make it difficult to ensure test coverage and even more difficult to determine if a part of the code is buggy or whether it found a hardware error that it was looking for. This is why diagnostics tend to be rather long affairs with very few functions. In my ANSI C code, you will see the following a lot: #define DO /*syntactic sugar */ DO {