< previous page page_a32 next page >

Page A32
General Guidelines
The style used in the programs and fragments throughout this text provide a good starting point for developing your own style. Our goals in creating this style were to make it simple, consistent, and easy to read.
Style is of benefit only for a human reader of your programdifferences in style make no difference to the computer. Good style includes the use of meaningful variable names, comments, and indentation of control structures, all of which help others to understand and work with your program. Perhaps the most important aspect of program style is consistency. If the style within a program is not consistent, then it becomes misleading and confusing.
Sometimes, a particular style is specified for you by your instructor or by the company you work for. When you are modifying someone else's code, you should use his or her style in order to maintain consistency within the program. However, you will also develop your own, personal programming style based on what you've been taught, your own experience, and your personal taste.
Comments
Comments are extra information included to make a program easier to understand. You should include a comment anywhere the code is difficult to understand. However, don't overcomment. Too many comments in a program can obscure the code and be a source of distraction.
In our style, there are four basic types of comments: headers, declarations, in-line, and sidebar.
1. Header comments appear at the top of the program and should include your name, the date that the program was written, and its purpose. It is also useful to include sections describing input, output, and assumptions. Think of the header comments as the reader's introduction to your program. Here is an example:
// This program computes the sidereal time for a given date and
// solar time.
//
// Written By: Your Name
//
// Date Completed: 4/8/96
//
// Input: A date and time in the form MM DD YY HH MM SS
//
// Output: Sidereal time in the form HH MM SS
//

 
< previous page page_a32 next page >