Coding Style Guidelines

Coding style is a bit like any style, everyone has their own style and it's hard to say that a style is wrong, but in coding there are some things that you should do. It's a little like wearing plaid with stripes, you can do it, but do you really want to?

Variables/Functions

When you are naming variables you want to follow these guidelines:

  1. Use names that have a meaning. For example t doesn't mean much, but table does.
  2. Try to avoid overly long or overly short names. For example, i is ok for say a loop counter, but not ok for a general purpose variable. ThisIsTheNAMEfor_MyReallyLongVariable may be legal, but it's really long and easy to get wrong. Go with a shorter one.
  3. I suggest that variable names start with a lower case letter. Then if you have more than one word in the name, use either camel case, e.g. myVariable, or an underscore to connect the variables, e.g. my_variable.

Comments

Variable Comments 1. Each variable should have a comment for it. The comment should describe the use of the variable.
2. The comments don't need to be super long, but should let someone know how the variable is going to be used.

Functions 1. Each function needs a comment before the implementation. The purpose of that comment is to give the name of the function, a short description, and it may list other items, e.g. the parameters, any preconditions or post-conditions. 2. See the example below

Each program will have a main function. The main function should have a comment that describes the overall program. It should list the programmer and the date it was written. This will be slightly modified for programs that are intended to be tested on Web-CAT, since Web-CAT will create the main.

Web-CAT Guidelines

So Web-CAT is a web based testing website that I use for most of my programming assignments. It allows you to submit your code multiple times and get hints if a test doesn't pass. It also allows you to work when it's convenient for you and if you are done at 3AM, great, I'll be asleep, you can tell me all about it later.

There are a few things to know about how I use Web-CAT that will make your life easier.

  1. If I specify the name for a header file, e.g. MyHeader.h, make sure you use the same spelling and capitalization. Web-CAT wouldn't fine myheader.h in this example.
  2. If I specify a function name with parameters, make sure the spelling and capitalization match here too. The order of the parameters is also important.
  3. In your code, if you have output that you'd like to see, use cout, not out. If it's output that Web-CAT needs to be able to read to grade, use out.
  4. In your code, if you need to read input, use in, not cin. There is no one at the keyboard in front of Web-CAT and when I test, I don't actually use cin. You can imagine I use a file and open it and give that to your program, if it helps.