home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / mystic.zip / PAS8.DOC < prev    next >
Text File  |  1986-02-27  |  6KB  |  173 lines

  1.  
  2.         Mystic Pascal  User Manual                                      76
  3.  
  4.  
  5.         11.  Programming Notes
  6.  
  7.  
  8.              This   section  contains  a  list  of  informal  programming 
  9.         suggestions.  Experienced programmers will find nothing new here.  
  10.         Users who are new to programming may find some tips here that are 
  11.         useful.
  12.  
  13.              Some  of  these  notes concern programming  in  general  and 
  14.         others are specific to Pascal.
  15.  
  16.  
  17.         1. Pascal procedures and functions should be kept small.  If they 
  18.         are 24 lines or smaller,  you can view an entire procedure on one 
  19.         CRT screen.
  20.  
  21.         2.  Give  meaningful names to all the program's  constants,  data 
  22.         types, variables, procedures and functions.  Mystic Pascal allows 
  23.         identifiers to be any length and all characters are  significant.  
  24.         When  meaningful  names are used,  your Pascal program  is  self-
  25.         documenting.
  26.  
  27.         3.  Use the programming technique of "stepwise refinement."  That 
  28.         is,  after you have completed the high level program design,  get 
  29.         some basic parts of the program running first, then gradually add 
  30.         more  features until the whole program is complete.   If you  can 
  31.         see interesting results from your program early on,  its good for 
  32.         your morale and makes work easier.   By using stepwise refinement 
  33.         you  can  focus your attention on one small objective at a  time.  
  34.         Debugging  is also simplified since any bugs will probably be  in 
  35.         the small areas most recently changed.
  36.  
  37.         4.  If  some  section  of  a program  gradually  evolves  into  a 
  38.         patchwork of changes and changes upon changes, it is usually best 
  39.         to  throw  it  out and reprogram that  section.   This  may  seem 
  40.         wasteful but you can probably reprogram some process in one fifth 
  41.         the  time  it originally took.   You will gain  a  cleaner,  more 
  42.         reliable,  more efficient piece of code.   
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.         Section 11:   Programming Notes
  58.  
  59.         Mystic Pascal  User Manual                                      77
  60.  
  61.  
  62.         5.  When  you  have a bug in your program that takes more than  5 
  63.         minutes  to resolve,  this simple technique may  be  surprisingly 
  64.         effective in organizing the debugging effort.
  65.  
  66.                   1.  Take a fresh sheet of paper -- it  really 
  67.                  is  important  to have a clean work area  free 
  68.                  from distracting unrelated information.
  69.  
  70.                   2.  Make a list of all known symptoms of  the 
  71.                  bug.
  72.  
  73.                   3. Make a list of 3 to 5 hypotheses which may 
  74.                  explain the error.
  75.  
  76.                   4.  Perform  further tests on the program  to 
  77.                  gather more information.   The tests should be 
  78.                  guided by the hypotheses.
  79.  
  80.                   5.  Proceed with testing, adding new symptoms 
  81.                  to the list,  deleting disqualified hypotheses 
  82.                  and  adding new hypotheses until the answer is 
  83.                  found.
  84.  
  85.              The  purpose of this technique is to clarify your vision  of 
  86.         the  problem state.   This procedure may lead very quickly  to  a 
  87.         solution  to difficult problems.   This is essentially the method 
  88.         used  by some types of artificial intelligence expert systems  to 
  89.         solve very hard problems.
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.         Section 11:   Programming Notes
  115.  
  116.         Mystic Pascal  User Manual                                      78
  117.  
  118.  
  119.         6.  When your program creates or modifies complex data structures 
  120.         it  is  extremely useful to have  a  validation  procedure.   The 
  121.         Mystic Pascal system itself contains validation code which checks 
  122.         over  the  structure of the Dynamic Storage and Laser at  regular 
  123.         intervals.   This code is activated every few seconds by the IDLE 
  124.         process.  
  125.  
  126.              Programs  which  create and maintain large linked  lists  or 
  127.         trees  in  dynamic  storage  or  which  maintain  complex  tables 
  128.         (arrays) of data are prone to program anomolies (bugs) which  can 
  129.         be  very hard to detect.   Since the computer is a master at  the 
  130.         tedious  and detailed inspection of minutae,  why not let it keep 
  131.         an eye on your exquisitely complex structures of data?  
  132.  
  133.              For  example,  if you are creating a linked list in  dynamic 
  134.         storage  using the NEW procedure,   a validation procedure  might 
  135.         travel  down the linked list examining each field in each  record 
  136.         for reasonable values.  When it finds some questionable value, it 
  137.         can  report  a  probable error and  perhaps  interrupt  the  main 
  138.         program.
  139.  
  140.              A  validation  procedure  may  be  called  every  time   the 
  141.         structure is modified or only after some major modifications.  Or 
  142.         in  Mystic  Pascal,  it  could  be implemented  as  a  concurrent 
  143.         procedure with a rather low priority.
  144.  
  145.              The  small  amount  of time needed  to  write  a  validation 
  146.         procedure for a complex data structure can be returned many times 
  147.         in  reduced debugging time.   
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.         Section 11:   Programming Notes
  172.  
  173.