home *** CD-ROM | disk | FTP | other *** search
/ Old Hackers Atari User Group Newsletter / Old_Hackers_Atari_User_Group_Newsletter_OHMJ93A.atr / jmodulr1.txt < prev    next >
Text File  |  2023-02-26  |  11KB  |  1 lines

  1.             <><><><>¢  MODULAR  PROGRAMMING IN ATARI BASIC!¢  ¢  This is Part I. (LOOK FOR PART II in¢  the  next  OL' HACKERS  newsletter!)¢¢  by Ron Fetzer-memberof OL'HACKERS NY¢  This article  has   been   submitted¢  to The ATARI CLASSIC magazine!¢¢      How  many times have you said "I¢ wish I could  write  a  long  program¢ like  Print  Shop"?  Have  you   ever¢ wondered  how these long professional¢ programs were written? Is there a way¢ I  could  write  a program like this?¢ The answer is yes! There is a  method¢ of  programming not widely know among¢ BASIC   programmers   called  Modular¢ Programming.     If    you    learned¢ programming by yourself, like I  did,¢ you  know  the  limitations  of Brute¢ Force programming. I usually hit  the¢ wall around 200 lines before I become¢ hopelessly lost.¢      There is an easy and better  way¢ of writing programs. If you can write¢ 15 lines of code then you  can  write¢ modular  programs  that easily exceed¢ the  memory  of  your  computer.  The¢ central idea of  modular  programming¢ is  that  you  break  a big task into¢ small units. Thus you  are  concerned¢ with only a small part of the task at¢ any one time. Programming will  again¢ become  fun  and very satisfying. The¢ academic  term  for  this  method  is¢ called Structured Programming. It has¢ been  kept  a   secret   from   BASIC¢ programmers  for  a  long  time.  The¢ professionals  use  it  all the time.¢ Atari BASIC is very well  suited  for¢ this method of programming because it¢ has a very compact structure that can¢ be learned very quickly.¢      If  you  use modular programming¢ you  will  write  short  modules  and¢ string  them  together  to  create  a¢ whole program.  You  will  have  many¢ benefits. 1. Your program now will be¢ easy to write the first time.¢ 2. Your program is easy  to  read  by¢ anyone.¢ 3.  It  can  be  changed  or modified¢ easily.¢ 4. Bugs can be found instantly.¢ 5. The program is self documenting.¢ 6. Large programs do  not  present  a¢ problem anymore.¢ 7. The programs will be elegant.¢ 8.  Programming will become fun again¢ because     there    is    no    more¢ frustration.¢¢      To start with you write out your¢ ideas for the program in English. You¢ make an outline just the way you  did¢ for  a  composition  in  High School.¢ Next you make a block  diagram.  That¢ shows  you  how many modules you need¢ and how they are connected. Then  you¢ write  a skeleton program. This is to¢ see that the modules execute  in  the¢ right  order.  Finally  you flesh out¢ the skeleton program into a  complete¢ program.¢¢      Writing the code for the program¢ is the easiest part and  should  take¢ the  least  amount  of   your   time.¢ Planning  the program should take the¢ most part of your  time.  This  looks¢ like a lot of work. It is not. It can¢ be sketched out  very  quickly.  Each¢ step leads to the next step. You have¢ now created a blue  print  to  follow¢ that is guaranteed to work. After you¢ have tried this method once you  will¢ never  go   back   to   Brute   Force¢ programming again.¢¢      In modular programming you start¢ out  with  the  most  general  module¢ first and then each succeeding module¢ becomes  more  specific.  The   first¢ module  is  the  control  module. The¢ control module is the head  or  brain¢ of  your  program.  It  controls your¢ program.   The  sub  modules  do  not¢ influence   the  control  module.  In¢ Atari  BASIC  you  use  the  GOSUB  -¢  RETURN function for all modules.¢¢      My better  half  the  other  day¢ said  "Dear can't you write a program¢ that  prints  the  addresses  on  the¢ Christmas Card Envelopes? Sticking on¢ labels looks so commercial". Thus was¢ born   the   idea   of  the  Envelope¢ program.   Why  stop  with  Christmas¢ Cards? Lets do business envelopes and¢ large  7 X 9 envelopes also. Below is¢ the outline in English of  the  ideas¢ that I want in my program.¢¢      ENVELOPE PROGRAM¢¢ I MAIN HEADING¢      A)DIM SECTION¢      B)SCREEN COLORS¢      C)RETURN ADDRESS¢      D)FORWARDING ADDRESS¢      E)MENU¢¢ II MENU¢      A)CHRISTMAS CARDS(5 X 7)¢      B)BUSINESS ENVELOPES(4 X 9.5)¢      C)LARGE ENVELOPES(7 X 9)¢      D)END¢¢ III PRINT SECTION¢      A)PRINT RETURN ADDRESS¢      B)PRINT FORWARDING ADDRESS¢¢      I want the user to have a choice¢ of screen colors while the program is¢ on  the  screen. The user should type¢ his return address only once and then¢ have  a choice of envelope sizes. The¢ menu should also have an  END  option¢ so the user can exit.¢¢      Now  I  have  a  general idea of¢ what I want in my program.  The  next¢ step  is  to  write  a block diagram.¢ This block diagram will show you  how¢ many  modules  you need and the range¢ of line numbers. Each line above will¢ become a module.¢¢      A  block  is  a  section of code¢ that performs one  action.  A  module¢ can  contain  one  or  more blocks. A¢ block as  well  as  a  module  should¢ follow the rule of straight sequence,¢ that is the entry point should be  at¢ the top and the exit at the bottom of¢ the block or module. Do not jump  out¢ of the module or block with a GOTO or¢ you will have spaghetti code.¢¢      It is important not to skip this¢ step. Sometimes you will have modules¢ calling   sub   modules  or  sub  sub¢ modules. Each module is in  the  form¢ of  a GOSUB - RETURN. For each module¢ I skip by 500 numbers to make it easy¢ on  myself.  The  block diagram below¢ follows the outline that I did before¢ in English.¢¢      ENVELOPE BLOCK DIAGRAM¢¢   10 -  499 CONTROL BLOCK¢  500 -  999 DIM SECTION¢ 1000 - 1499 SCREEN COLORS¢ 1500 - 1999 ENTER RETURN ADDRESS¢ 2000 - 2499 MENU¢ 2500 - 2999 ENTER FORWARDING ADDRESS¢ 3000 - 3499 * CHRISTMAS ENVELOPES¢ 3500 - 3999 * BUSINESS ENVELOPES¢ 4000 - 4499 * LARGE ENVELOPES¢ 5000 - 5499 PRINT RETURN ADDRESS¢ 5500 - 5499 END¢ *  These  modules  use  also  the sub¢ modules of PRINT RETURN  ADDRESS  and¢ FORWARDING ADDRESS.¢¢      The  control  module  calls  all¢ other  modules.  Each  module returns¢ eventually   to  the  control  module¢ where it is  directed  again  to  the¢ menu  module.  A good program is easy¢ to   read,   consistent   and    self¢ documenting.  You  now have a outline¢ of   your   program   with   all  its¢ modules.¢¢      It is now so easy to  set  up  a¢ skeleton    program.   The   skeleton¢ program   will  confirm  the  correct¢ execution of your modules.  Later  on¢ the skeleton program gets fleshed out¢ to the full program. Each  module  in¢ the  skeleton  program  will  have  a¢ PRINT  statement  in  it  to show the¢ function   of  the  module  when  the¢ program is run.  Later  on  when  you¢ flesh  out  the  skeleton program you¢ will take out this print line.  Below¢ is the skeleton program.¢¢      ENVELOPE SKELETON PROGRAM¢¢ 0 GOTO 10¢ 1 SAVE "D:SKELETON.ENV":CLR¢ 5    REM    SKELETON    PROGRAM   FOR¢ "ENVELOPE.ATR" VER 1.0 IN ATARI BASIC¢ BY RON FETZER 9/92¢ 10            REM             CONTROL¢ MODULE*******************************¢ ******¢ 20   ?  CHR$(125):GOSUB  500:REM  DIM¢ SECTION¢ 30 GOSUB 1000:REM SCREEN COLORS¢ 40 GOSUB 1500:REM RETURN ADDRESS¢ 50 GOSUB 2000:REM MENU¢ 60 GOTO 50¢ 500              REM              DIM¢ SECTION******************************¢ *********¢ 510 ? :? "DIM SECTION":GOSUB 30000¢ 520 RETURN ¢ 1000            REM            SCREEN¢ COLORS*******************************¢ *****¢ 1010   ?   :?  "SCREEN  COLORS":GOSUB¢ 30000¢ 1020 RETURN ¢ 1500            REM            RETURN¢ ADDRESS******************************¢ *****¢ 1510  ?  :?  "RETURN   ADDRESS":GOSUB¢ 30000¢ 1520 RETURN ¢ 2000                              REM¢ MENU*********************************¢ ************¢ 2010 ? :? "           MENU:":? :? ¢ 2020 ? "1. CHRISTMAS CARDS(5 X7)"¢ 2030 ?  "2.  BUSINESS  ENVELOPES(4  X¢ 10)"¢ 2040 ? "3. LARGE ENVELOPES(7 X 9)"¢ 2050 ? "4. END"¢ 2060  ?  :?  "             SELECT   A¢ NUMBER";:INPUT N¢ 2070 ON N GOSUB 3000,3500,4000,5500¢ 2080 RETURN ¢ 2500          REM          FORWARDING¢ ADDRESS******************************¢¢ 2510 ? :? "FORWARDING  ADDRESS":GOSUB¢ 30000¢ 2520 RETURN ¢ 3000          REM           CHRISTMAS¢ CARDS********************************¢ *¢ 3010 ? CHR$(125):GOSUB 5000¢ 3020 GOSUB 2500¢ 3030   ?   :?  "CHRISTMAS  CARDS(5  X¢ 7)":GOSUB 30000¢ 3040 RETURN ¢ 3500           REM           BUSINESS¢ ENVELOPES****************************¢ ****¢ 3510 ? CHR$(125):GOSUB 5000¢ 3520 GOSUB 2500¢ 3530 ? :? "BUSINESS ENVELOPES  (4  X ¢ 9.5)":GOSUB 30000¢ 3540 RETURN ¢ 4000            REM             LARGE¢ ENVELOPES****************************¢ ******¢ 4010 ? CHR$(125):GOSUB 5000¢ 4020 GOSUB 2500¢ 4030   ?   :?  "LARGE  ENVELOPES(7  X¢ 9)":GOSUB 30000¢ 4040 RETURN ¢ 5000       REM      PRINT      RETURN¢ ADDRESS******************************¢ 5010    ?    :?     "PRINT     RETURN¢ ADDRESS":GOSUB 30000¢ 5020 RETURN ¢ 5500                              REM¢ END**********************************¢ ************¢ 5510  ?  :?  "END  OF  PROGRAM":GOSUB¢ 30000¢ 5520 END ¢ 5530 RETURN ¢ 30000 REM TIME DELAY LOOP  USED  ONLY¢ IN      THE      SKELETON     PROGRAM¢ *************************************¢ ********************¢ 30010 FOR T=1 TO 180:NEXT T¢ 30020 RETURN ¢ 30030¢ REM**********************************¢ ***********************¢¢      I  separate  each  module with a¢ REM and the module name. Then I  fill¢ in  the  rest of the module separator¢ with   asterisks  until  I  have  two¢ screen  lines.  In  this  way  I  can¢ separate very clearly each module  in¢ the program.¢¢      The  time  delay  loop  in lines¢ 30000 to 30020 is used  only  in  the¢ skeleton  program  to  slow  down the¢ execution of  the program so you  can¢ see if it executes correctly.¢¢       In    conclusion   in   modular¢ programming the most  important  part¢ is the planning. Write out an outline¢ in English  of  your  ideas  for  the¢ program.  You  must  set  up  a block¢ diagram  to  show  what  modules  you¢ need. The control  module  should  be¢ the  first  module.  You must write a¢ skeleton   program  to  see  if  your¢ program will execute correctly.¢¢      Each block and module follow the¢ law  of  straight sequence. You enter¢ at the top and exit at the bottom  or¢ the  end of the block or module. This¢ is the natural expectation in reading¢ a  sequence  and   thus   should   be¢ followed  without  fail.  Do not jump¢ out of a block or  a  module  with  a¢ GOTO.¢¢      Now it will be so easy to finish¢ your program. You know it will  work.¢ You  know  that you can complete each¢ module at your leisure. You know  you¢ can  find  a  bug instantly. You know¢ you are going to be successful.¢¢       Programming   will  become  fun¢ again. You now can be proud  of  your¢ program, not only does it work but it¢ is also professionally written.  Your¢ program  now  will  compare  with the¢ best of them.¢¢      In the 2nd part of this series I¢ will  show  you  how to flesh out and¢ polish your program and complete it.¢¢      I am a member of the OL' HACKERS¢ ATARI  USERS  GROUP in Oceanside N.Y.¢ If you want more  materials  on  this¢ subject  we  have  the   "PROGRAMMING¢ KIT".  It  is  a  3 disk double sided¢ disk set. It discusses  this  subject¢ in  greater  detail  and  uses  TURBO¢ BASIC. It is available for $7.00 from¢ us. Write to Alex Pignato, 3376 Ocean¢ Harbor  Dr.,  Oceanside  N.Y.  11572.¢ Make  the  check   payable   to   Ron¢ Fetzer.¢¢        LOOK FOR PART 2¢              <><>¢