home *** CD-ROM | disk | FTP | other *** search
/ Futura 9 / Futura_Issue_09_1993_09_NOSAUG_Side_A_BASIC.atr / flyer.doc < prev    next >
Text File  |  2023-02-26  |  10KB  |  1 lines

  1. ¢    The following article by Ron Fetzer is from the Turbo BASIC Flyer (Summer 1989) and is also included in Ron's Turbo BASIC Programming Kit.  Even if you already have the Kit, this article is well worth re-reading!¢¢¢***************************¢** THE TURBO BASIC FLYER **¢***************************¢¢PROGRAMMING MADE EASY¢by Ron Fetzer, OHAUG.¢¢    When I was a beginning programmer I always wondered how these long programs were written.  I said to myself "Boy this must be some smart guy who did this!"¢¢    As most of us who learn programming by ourselves we start with "BRUTE FORCE" programming.  With this method you can write about 100 to 150 lines before you hit the wall and become hopelessly lost.¢¢    There is a better way!  Anyone who can write 15 to 20 lines can write a program that can easily exhaust the memory of your Atari computer.  The academic term for this method is called STRUCTURED PROGRAMMING.  That term has very little meaning to most of us.  I call this method MODULAR PROGRAMMING.¢¢    In modular programming you write short modules and then string them together.  TURBO-BASIC is especially suited to MODULAR PROGRAMMING.¢¢    You will have the following benefits if you use this method.¢¢ 1. Programs are easy to write the¢    first time.¢ 2. Programs are easy to read.¢ 3. Programs are easy to change¢ 4. Programs are easy to take apart¢ 5. Programs are self documenting¢ 6. Long programs are easy to write¢¢    In modular programming you write the MOST GENERAL MODULE FIRST, such as the CONTROL MODULE.  Then you write the more specific modules such as 'GET THE DISK DIRECTORY' etc.  You go from GENERAL to SPECIFIC as far as modules are concerned.  This is called TOP DOWN PROGRAMMING.¢¢    In actual practice you write out a list of all the things you want your program to do.  Each action becomes a module.  The modules are written as subroutines.  In TURBO-BASIC we use PROC -ENDPROC.  In Atari Basic you would use GOSUB.¢¢    It is like making an outline of a report.  You have a title, main heading and sub headings.  You start out very general and become more and more specific.¢¢    The MAJORITY of your time should be spent planning an outline of the program and constructing a block diagram.¢¢    The advantage of doing modular programming is that you break a problem into small chunks.  You work with one module at a time ignoring all the rest.¢¢    A good program is easy to read, self documenting and usually elegant with very little REM lines in it.¢¢    A good program requires careful planning, consistency, good form and structure.  Filling in the code is usually the EASIEST part of the process.¢¢    Purist in STRUCTURED PROGRAMMING maintain that you should use GOTO as little as possible or not at all because it leads to SPAGHETTI CODE.  I maintain a judicious use of GOTO is all right as long as you do not jump outside the module with the GOTO.¢¢    Your goal in each module should be to obey the LAW OF STRAIGHT SEQUENCE.  That is your entry point to the module is at the top and your exit point of the block or module is at the bottom.  In other words we should not have a GOTO to jump outside the module.¢¢    A module may have several blocks.  That is several commands that perform a specific action.  They should also be ONE-IN/ONE-OUT type of blocks.  You enter in at the top and you exit out at the bottom.¢¢    I am going to do a program in MODULAR TURBO-BASIC called 'DISK SECRETARY'.  I will go step by step to show how it is done.¢¢    My DISK SECRETARY program should list a disk directory in 2 columns on the screen or the printer.  It should give me the free disk space available in K. bytes rather than sectors.  It should work with single, 1050 and double density disks.  It should give me most of the DOS functions so I can manipulate the files.  It should work with disk drive No 1, 2 and RAM DISK D8.¢¢¢OUTLINE IN ENGLISH¢¢   I GENERAL SECTION¢        Ia Screen Colors¢        Ib Dim Section¢        Ic Density & Drive info.¢¢  II MENU SECTION¢        IIa Print to Screen¢        IIb To Printer¢            a1&b1 Convert free¢                  Sectors to K-Bytes¢        IIc Lock a File¢        IId Unlock a File¢        IIe Rename a File¢        IIf Delete a File¢        IIg Format¢            g1 Single Density¢            g2 1050 Density¢        IIh End¢¢    Each sub section will become a PROC-ENDPROC SUBROUTINE.  It will be a closed module.  The modules are separated by the -- COMMAND.¢¢¢MAKING A BLOCK DIAGRAM¢¢    It is MOST IMPORTANT that you make a BLOCK DIAGRAM of your program.  I usually allocate 50 lines for each module.  Sometimes you will have modules calling other modules or subroutines within subroutines.¢¢¢DISK SECRETARY BLOCK PROGRAM¢¢ **************¢ 10 - 490¢ CONTROL MODULE¢ **************¢¢ **************¢ 500 - 990¢ SCREEN COLORS¢ **************¢¢ **************¢ 1500 - 1990¢ DENSITY INFO¢ **************¢¢ **************¢ 2000 - 2490¢ MENU¢ **************¢¢ **************¢ 2500 - 2490¢ PRINT TO SCRN*¢ **************¢¢                    ****************¢                    6500 - 6900¢                    CONVERT FREE SEC¢                    Subroutine for¢                    Screen/Printer¢                    ****************¢¢ **************¢ 3000 - 3490¢ TO PRINTER¢ **************¢¢ **************¢ 3500 - 3990¢ LOCK A FILE¢ **************¢¢ **************¢ 4000 - 449¢ UNLOCK A FILE¢ **************¢¢                    ***************¢                    7000 - 7490¢                    FILE NAME¢                    Subroutine for¢                    Lock/Unlock/¢                    Delete¢                    ***************¢¢ **************¢ 5000 - 5490¢ RENAME A FILE¢ **************¢¢ **************¢ 5500 - 5590¢ DELETE A FILE¢ **************¢¢ **************¢ 6000 - 6490¢ FORMAT SD/1050¢ **************¢¢ **************¢ 7500 - 7990¢ END¢ **************¢¢¢    The first module is the CONTROL MODULE.  All other modules below it are sub modules.  Each sub module will return to the CONTROL MODULE via the  MENU MODULE.¢¢    In the MENU MODULE when a choice is made and the appropriate action has been completed then the program returns to the ENDPROC.  After this the program goes back to the CONTROL MODULE line 70.  Line 70 directs the program again to the MENU MODULE.  This kind of a program is called a CASE STRUCTURE type of program.¢¢    No sub module will make decisions that must be followed by the CONTROL MODULE.  Some modules will call other modules and sub sub modules.  Each module will exit with ENDPROC.¢¢¢THE SKELETON PROGRAM¢¢    The skeleton program is a program where you set up each module.  Each module will have a PRINT to identify the function of the module.¢¢    The reason we make a skeleton program is to verify that our BLOCK PROGRAM will execute in the right order.  Each block becomes a module.¢¢    When we do the coding the PRINT line will be removed from each module.  It is IMPERATIVE that you make a SKELETON PROGRAM.¢¢¢SKELETON PROGRAM¢¢¢  10 REM DISK SECRETARY BY RON FETZER¢  20 ------------------------------¢  30 EXEC SCRN_CL¢  40 EXEC DIM_SEC¢  50 EXEC DENST¢  60 EXEC MENU¢  70 GOTO 60¢ 490 ------------------------------¢ 500 PROC SCRN_CL:CLS ¢ 510   ? "SCREEN COLORS":PAUSE 60¢ 980 ENDPROC ¢ 990 ------------------------------¢1000 PROC DIM_SEC:CLS ¢1010   ? "DIM SECTION":PAUSE 60¢1480 ENDPROC ¢1490 ------------------------------¢1500 PROC DENST:CLS ¢1510   ? "DENSITY INFORMATION"¢1520   ? "DRIVE 1, 2 OR 8":PAUSE 120¢1980 ENDPROC ¢1990 ------------------------------¢2000 PROC MENU:CLS ¢2010   ? :? "       MENU":? ¢2020   ? "1. DISK DATA"¢2030   ? "2. DIRECT. TO SCREEN"¢2040   ? "3. DIRECT. TO PRINTER"¢2050   ? "4. LOCK A FILE"¢2060   ? "5. UNLOCK A FILE"¢2070   ? "6. RENAME A FILE"¢2080   ? "7. DELETE A FILE"¢2090   ? "8. FORMAT A DISK"¢2100   ? "9. END"¢2110   ? :? :INPUT "   SELECT A¢       NUMBER";NUM¢2120   On NUM EXEC DENST,SCRN,PRNT,LOK,¢       UNLOK,RENAM,DELET,FORMT,FINI¢2480 ENDPROC ¢2490 ------------------------------¢2500 PROC SCRN:CLS ¢2510   ? "DIRECTORY ON THE¢         SCREEN":PAUSE 60¢2900   EXEC CONVRT¢2980 ENDPROC ¢2990 ------------------------------¢3000 PROC PRNT:CLS ¢3005   EXEC SCRN¢3010   ? "DIRECTORY TO THE¢       PRINTER":PAUSE 60¢3400   EXEC CONVRT¢3480 ENDPROC ¢3490 ------------------------------¢3500 PROC LOK:CLS ¢3510   EXEC SCRN¢3520   EXEC FILE¢3530   ? "LOCK A FILE":PAUSE 60¢3540   EXEC SCRN¢3980 ENDPROC ¢3990 ------------------------------¢4000 PROC UNLOK:CLS ¢4010   EXEC SCRN¢4020   EXEC FILE¢4030   ? "UNLOCK A FILE":PAUSE 60¢4040   EXEC SCRN¢4480 ENDPROC ¢4490 ------------------------------¢5000 PROC RENAM:CLS ¢5010   EXEC SCRN¢5030   ? "RENAME A FILE":PAUSE 60¢5040   EXEC SCRN¢5480 ENDPROC ¢5490 ------------------------------¢5500 PROC DELET:CLS ¢5510   EXEC SCRN¢5520   EXEC FILE¢5530   ? "DELETE A FILE":PAUSE 60¢5540   EXEC SCRN¢5980 ENDPROC ¢5990 ------------------------------¢6000 PROC FORMT:CLS ¢6010   ? "FORMAT":PAUSE 60¢6480 ENDPROC ¢6490 ------------------------------¢6500 PROC CONVRT¢6510   ? "CONVERT SECTORS TO¢       K-BYTES":PAUSE 60¢6980 ENDPROC ¢6990 ------------------------------¢7000 PROC FILE¢7010   ? "FILE NAME INPUT":PAUSE 60¢7480 ENDPROC ¢7490 ------------------------------¢7500 PROC FINI:CLS ¢7510   ? "END OF PROGRAM":PAUSE 60¢7970   END ¢7980 ENDPROC ¢7990 ------------------------------¢¢¢¢SUMMARY¢¢    In MODULAR PROGRAMMING the most important steps are writing the BLOCK DIAGRAM and the SKELETON PROGRAM.¢¢    Planning is TOP DOWN.  The CONTROL MODULE is the most general and the sub modules are the most specific.¢¢    Modules are self contained units using PROC - ENDPROC.  The entry point of each module is at the top.  The exit point is at the bottom.  Modules follow the LAW OF STRAIGHT SEQUENCE.¢¢    Modules can have several BLOCKS in them.  A block is a section of code that perform a specific action.  They also follow the ONE-IN/ONE-OUT rule. You separate the modules with the -- command.¢¢    The SKELETON PROGRAM verifies that the program is executed in the right order.  Later on the SKELETON PROGRAM is fleshed out.¢¢    The conclusion of this article will be on the next issue of this disk.  Then we will flesh out the SKELETON PROGRAM and fill in the modules with the actual code.¢¢¢    Your comments are welcome! Please write to:¢¢          RON FETZER¢          22 MONACO AVE¢          ELMONT N.Y. 11003¢          U.S.A.¢¢¢-----¢¢¢Ed: Ron Fetzer's Disk Secretary (SECRTARY.TUR) will be on Futura issue 10.¢