Thursday, September 26, 2013

P2C5: Writing maintainable programs

Outlines

  1. Programming terminology:
    • A variable is a data item associated with a memory location of which the value can change.
    • A constant is a data item associated with a memory location of which the value can't change. If the value needs to change, it is changed once and the program is recompiled.
    • An identifier is a name that represents an element in a program such as a variable, a constant, a function, a procedure, a user-defined data type or an object.
    • A reserved word, or keyword, is one that is defined by the programming language, such as int or switch in C#.Net.
  2. Variables must usually be declared so that the computer knows how much space to allocate and the type of data to which they refer.
  3. The identifier name for a variable or constant must be unique and not a reserved word. It should be meaningful.
  4. Variables should be initialized appropriately before using them
  5. Variables have a scope within the program code:
    • a variable which is recognised everywhere in the code is said to be a "global" variable
    • a variable may be "local" to a procedure or function.
  6. Uses followings for good readability of source codes:
    • comments
    • indentation and formatting to show the control structures (i.e. if statements and loops)
    • white spaces



No comments:

Post a Comment