Programming Fundamentals

Computer Science 115
Fall 2004

Main | Syllabus | Grading | Programming Style | Honor Code

*A PROGRAMMING STYLE GUIDE FOR THIS COURSE

This is the programming style guide for Computer Science 115. Part of your grade on labs and projects will depend on how well you follow these guidelines, so keep a copy handy, or remember where you can find it online!

* THE BASICS OF GOOD DOCUMENTATION

The key to writing good computer programs comes in several pieces. Obviously, the design and correctness of the program itself is an important part. However, a part which is equally important is the documentation. We never write programs in a void; we are always part of a larger community, whether that community involves fellow students, professors in a programming course, or co-workers in a future job. Almost always, there will be someone who is going to have to read this program after you have completed it, and that someone is going to have to be brought up to speed on what you were trying to do and how you were doing it. That someone could be you; you would be surprised how hard it is to remember how a program was written only a few weeks after you put it aside!

This is why most (if not all) modern computer programming languages include some way to provide documentation alongside your program itself. This documentation is ignored by the computer, but any human reading your program will be thankful for it.

When you provide documentation for any program, you should keep the following factors in mind:

The rest of this guide goes into specifics on the expectations regarding the form your documentation should take.

* COMMENTS

The primary vehicle for documenting a program is the comment, an aside within the program itself that is "invisible" to the computer. In this course, you should always provide the following comments at a minimum:

* INDENTATION AND OTHER WHITESPACE

While C++ does not require you to indent your code, nor in fact to include any whitespace at all if you wish to smush all of your statements together on one line and never use the spacebar, the return key, or the tab key, it is a necessity for readability that you use all of these three keys in good amounts. Code surrounded by curly brackets (braces) sould always be indented a minimum of 3 spaces from the surrounding code. Other whitespace should be used as you see fit to space out your code and make it easier to follow.

* VARIABLE AND FUNCTION NAMES

It goes without saying that variable names such as x and y are not very informative, and should not be used for many purposes other than as loop indices. Do not be stingy with the names you give to your variables, functions, and object classes. Do not be cryptic, either. Allow them to be descriptive. Even when you comment their declarations, a reader will best remember that identifier's purpose if the identifier is easy to read.

* FUNCTION STRUCTURE

A wise man once said: "A function should never be larger than one screen." Functions that stretch on for hundreds of lines are not following a modular structure; they should be broken down further into smaller functions. Screen sizes vary, but this general guideline helps give you a heads-up when a function is getting out of control.

 

Free Original Clipart at Designed to a T