style - Programming Style Guidelines Basic Requirements...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming Style Guidelines Basic Requirements Header Comments All files should have a set of comments at the top of the file: // Adds two numbers - What the contents of the file are for // Project #1 Add Program - The assignment name and class if the file is part of a class program assignment. // CS 23021 // John H. Doe - Who wrote the program // 9/14/99 - The date the program was created or last modified Style For some of the guidelines there is a choice of different personal styles that you could use. You should pick a style for a program and use it consistently. Inconsistent use of a style is bad style. Declaring Variables Variables should be declared as close as possible to where they are going to be used. If a variable can be, make it as local to the block that it is being used in. Note, that if a variable is used in multiple places of a block, then it should be declared at the beginning of the block rather than close to its first place of use. Variables should also be given an initial value. The only exception would be the following: int n; cin >> n; Identifier Names Identifiers, things you get to name in a program such as variables, constants, etc., should be given clear names. If you are not able to come up with a good name for an identifier then you need to think some more of what the variable is for. The length (and descriptiveness) of the identifier (especially variables) depends on the distance from declaration to use. If it is a global variable which is used in different places throughout a program, its identifier should convey its intended purpose so as to remind the programmer what this variable is for. If it is a variable declared and immediately used to, for example, temporarily store value, tmp is good enough. For example: int tmp;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// swapping values of a and b tmp=a; a=b; b=tmp; Comments Comments in a program allow the programmer to clearly express the what and why the statements are there. The program statements that are written are there for a reason. The reason should be expressed in the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/22/2010 for the course CS 23021 taught by Professor Staff during the Spring '08 term at Kent State.

Page1 / 5

style - Programming Style Guidelines Basic Requirements...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online