From Pat Winstanley · 1996-03-30 18:31 · #75159 in R25C
In reply to comments etc by Bill Birrell
Hi Bill, Friday March 29 1996 16:47, Bill Birrell wrote to Allan Findlay: >> IMHO: Comments should be used for things which aren't >> obvious or just >> need to be explained there is nothoing more annoying >> than a screen full >> of comments which don't say anymore then the code >> does. BB> Sound common sense, Allan. I go along with all of that. A trick I picked up from somewhere is to write pseudocode as a series of one-line comments when designing an algorithm, but to write them *in* the code areas. These one-liners then describe the gist of the code filled in later. For instance: // Loop through the grid cells ........................... // Get contents of neighbouring cell ............................. ............................ ............................ // Get contents of current cell ............................. ............................. ............................ // End loop The dotted lines are actual code as it is filled in, and generally each code block goes off to be a function of its own later, named as a short version of the pseudo code. The comments say what I'm attempting to do, rather than describe how I'm doing it. Each spin-off function generally has a slightly more explanatory header comment, to allow for the preceding and following blocks being elsewhere... such as: // Returns value of array element, called by general routine to check cell // contents against neighbours. Result to be stored in the temp array. The above is taken from a 'game of life' exercise from college, which was actually coded in VB, but the logic in the brief comments can (and will) be transferred over to any other language. It's totally generalised. The 'what', not the 'how'. This method also has the advantage of showing up bits of code that haven't been done yet! :-) Pat --- * Origin: Pierless, Wigan, UK. [01942-749012 (cable)] (2:250/107.99)