Programming Practice: Programming Guidelines

  • Programming temple
    • all program follow a temple contains:
    • original program author
    • subsequent modification author
    • dates
    • preamble used for include file
      • ex. using namespace std;
    • standard include files
      • #include <>
    • a standard point(main function)
  • Data definition
    • set of data structure program need base on description
    • preamble
      • comment for statement of purpose
    • definition
      • obvious
      • use typedef to describe a specific data type even for a int(keep code clear)
      • common forms of data
        • discrete entities(a variable have several possible value)
          • use enum
        • structured entities(a variable contain several field)
          • use struct
        • variant entities
          • use union and an enum to tag variant
        • recursive entities
          • ex. structure have pointer point to another same type structure
    • usage-temple
      • a temple lists a set of usual procedure forms of data
      • write below data definition
    • constructors for base cases of data
    • constant related to data type
    • follow data definition and usage temple
  • Module, Function, Subprogram Temple
    • Module temple
      • Contract
        • name of procedure(程序), types of arguments it excepts and its return type, and any assumptions
      • Purpose
        • statement about what procedure is intend to do
          • each argument and return value
      • Stub
        • C/C++ prototype of procedure and initially a stub return a working value(not  must correct)
  • get help from compiler
    • usage of -Wall, -Wextra, -pedantic

留下评论