CSCE 315 Lecture 2
Jump to navigation
Jump to search
« previous | Friday, January 20, 2012 | next »
Naming
- variables
- functions
- types/classes
- namespaces
- macros
- files
Sometimes there are naming conventions: follow it
Wise names:
- not a reserved name
- informative (say what it does Print() vs PrintAndCloseFile())
- concise
- memorable
- pronounceable (so when you talk with others)
More description in larger scopes (global vars)
Procedures should be verb names and functions should include return type
Booleans should be is*()
Beware of
var temp;
- reusing variable names
- overloading names
- intentional misspellings
Conventions
- Pointer vars start with p
- Numbers start with n
- i and j are integer indices
Layout and Style
Indentation, placement of curly braces and syntax
Fundamental Theorem of Formatting: Good visual layout shows the logical structure of the program.
Avoid ternary inline IF statements
Avoid using NOTs in conditionals (be positive)
if (!(z>=0) && !(z<a))
if ((z<0) && (z>=a))