Why does COBOL have both `SECTION` and `PARAGRAPH`?

后端 未结 9 1224
一向
一向 2021-02-18 16:23

Why does COBOL have both SECTION and PARAGRAPH?

Can anybody explain why the designers of COBOL created both SECTIONs and PAR

9条回答
  •  闹比i
    闹比i (楼主)
    2021-02-18 16:45

    Well, the simplest of the reasons is that SECTION s provide you the "modularity" -- just as functions in C -- a necessity in the "structured" programs. You would notice that code written using SECTIONs appears far more readable than the code written just in paragraphs, for every section has to have an "EXIT" -- a sole and very explicit exit point from a SECTION (exit point of a paragrpah is far more vague and implicit, i.e. until a new paragraph declaration is found). Consider this example and you may be tempted to use sections in your code:

    *==================
     MAINLINE SECTION.
    *==================
         PERFORM SEC-A
         PERFORM SEC-B
         PERFORM SEC-C
         GOBACK.
    *==================
     MAINLINE-EXIT.
    *==================
        EXIT.
    
    *==================
     SEC-A SECTION.
    *==================
    
    .....
    .....
    .....
    .....
    
        IF 
           go to A-EXIT
        end-if
    
    ..... 
    .....
    .....
    .....
    
    .
    
    *==================
     A-EXIT.
    *==================
        EXIT.
    

    Don't think you would have this sort of a privlege when writing your codes in paragraphs. You may have had to write a huge ELSE statement to cover up the statements you didn't want to execute when a certain condition is reached (consider that set of statements to be running across 2-3 pages... a further set of IF / ELSE would cramp you up for indentation). Of course, you'll have to use "GO TO" to achieve this, but you can always direct your professionals not to use GO TOs except while Exiting, which is a fair deal, I think.

    So, whilst I also agree that anything that can be written using SECTIONs can also be written using paragraphs (with little or no tweaks), my personal choice would be to go for an implementation that can make the job of my developers a little easier in future!

提交回复
热议问题