Terms & Programming Style in COMP 150

(Revised 01/06/2007)


Important and Useful Terms

syntax vs. semantics

variable : variables are implemented as named storage location in memory (see Data Types)

identifiers

data type: set of values plus operations on those values

I/O streams: streams of ASCII characters separated by newline characters

escape sequences (C++ only)

numeric types

floating point types (type double)

other types

type compatability

assignment statements

arithmetic operations


 

Programming Style Requirements - Level 1

General Rule: Form Follows Function


1.    Use meaningful identifier names for variables and constants

A.    An identifier name should describe its use
B.    Use lower case letters for variable identifiers
C.    Use underscore or capital letters ("camel" notation) to separate words in two word identifiers

example: gross_pay or grossPay

D.    Use upper case letters for named constants (C++ only)

Example: const double PAY_RATE = 9.95;

E.    Declare constants before variables (C++ only)

 2.    Code Layout: Indenting

A.    Indent the bodies of “while” and “for” loops at least 4 spaces
B.    Indent statements subordinate to "if" and "else" at least 4 spaces
C.    Place braces that define the bodies of loops or subordinate statements on separate lines (C++ only)
D.    Indenting levels are cumulative!

3.    Code Layout: Vertical Spacing

A.    A group of statements that perform a well defined task is called a logical block. Skip a line before and after logical block to separate them.
B.    Skip lines before and after comments
C.    An “if else” statement requires at least four lines since the "if (condition)" and "else" appear on separate lines

 4.    Comments

A.    Comments describe "what" is being done - not how
B.    Comments must be
clear, concise, correct and complete
C.    Do not comment the obvious
D.    Logical blocks of code should be commented
E.    Attach comments to statements only if the code is obscure.


Return to COMP 150 HomePage