From: magnus@amp;thep.lu.se (Magnus Olsson) Newsgroups: alt.folklore.computers Subject: Re: COBOL Date: 25 Jan 92 12:46:54 GMT In article <1992Jan24.205955.3584@amp;ibmpa.awdpa.ibm.com> email@example.com (Larry Breed) writes: >Back in the 50's when cobol was being designed, it was touted as "the >computer language that vice presidents can read." No longer need they >rely on technical experts whose only value was their ability to >read and write assembler! Hence the Real English syntax above. This makes me think of the following spoof article by an unknown author (the only thing known about "Tom A. Crona" is that it's a pseudonym) that was floating around on Vega.ldc.lu.se, the late CS VAX here in Lund, a few years ago. (If you ask nicely, I may post the first two parts, that deal wwith Fortran and Pascal, too). Magnus Olsson | \e+ /_ Dept. of Theoretical Physics | \ Z / q University of Lund, Sweden | >----< Internet: magnus@amp;thep.lu.se | / \===== g Bitnet: THEPMO@amp;SELDC52 | /e- \q * BORED BY PASCAL? part 3 * ======================= * With the advent of Pascal, the art of writing interesting code is quickly * dying out among the younger programmers. I must confess that Pascal has * made it possible for (almost) everyone to write working programs, * but it also acts to stifle the true creativity expressed when writing * (and trying to debug) self-modifying, spaghetti-structured programs * written in any of the REAL programming languages. The only hope of * rescue for the "lost generation" of brand-new Pascal "programmers" is * to learn another language which is better suited for REAL programming. * In the previous articles of this series we have discussed * (i) the advantages of real, old-fashioned FORTRAN (not that miserable * pseudo-Pascal known as FORTRAN 77) * (ii)the possibility of writing your programs in BASIC and then translating * them directly into Pascal. * Some people may be repelled by the short and concise notation of these * languages - they are suffering from the illusion that a program has * to be self-explanatory so that every idiot can understand it. * (in fact it's advantageous to write incomprehensible program since in * that case you (and not your competitors) will be called in to modify * it when it's found out that the program won't function because the * problem was incorrectly stated.) * There is a cure even for these unfortunate people, however. It's called * COBOL. The most distinct feature of this language is that it's extremely * verbose - in fact COBOL is more like a subset of English than a * programming language! * While this will (probably) take care of the need for documentation, * COBOL still has the properties that encourage creative programming, * like for example: * * + The total absence of any "structured" language elements * + The lack of local variables forcing you to remember all the * variables you're using (good for your memory if it's a long program) * + The possibility of writing subroutines with multiple entry and * exit points (not even BASIC has this last feature!) * + The ALTER statement for writing self-modifying code (see below) * + The good old GO TO statement enabling you to give the program * any kind of structure you like. * * You should not be frightened by the fact that COBOL is said to be a * language for commercial programming. Below is a pure computational * program (it solves one of those nasty cubic equations) * written in COBOL which functions quite excellently. (Besides, I have * met programmers who actually write accounting programs in Algol...) * * Since the reader may not be acquainted with the semantics of COBOL, * I have departed from my holy principles and inserted some comments * into the code. IDENTIFICATION DIVISION. PROGRAM-ID. SOLVE-CUBIC. AUTHOR. TOM A CRONA. INSTALLATION. LDC. DATE-WRITTEN. OCTOBER 22,1984. DATE-COMPILED. OCTOBER 22,1984. SECURITY. NONE. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. VAX. OBJECT-COMPUTER. VAX. SPECIAL-NAMES. DECIMAL-POINT IS COMMA. DATA DIVISION. * If you think the variable declarations in Pascal are long and tedious, * have a look at this: WORKING-STORAGE SECTION. 77 ROOT-1 PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 ROOT-2 PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 EPS PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 X PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 OLD-X PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 LAST-X PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 NEW-X PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 Y PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 Y1 PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 Y2 PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 TEMP PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 TEMP2 PICTURE S999V9(9) USAGE IS COMPUTATIONAL. 77 EDITED-NBR PICTURE ---9,9(9) USAGE IS DISPLAY. 77 ITERATIONS PICTURE 99 USAGE IS COMPUTATIONAL. * I'm not going to tell you what all this means - consult the nearest * COBOL reference manual. PROCEDURE DIVISION. COMPUTE-ROOTS. DISPLAY "THIS PROGRAM SOLVES 63x^3-9x^2-7x+1=0". COMPUTE EPS = 10 ** -5. PERFORM SOLVE THROUGH END-SOLVE MOVE LAST-X TO ROOT-1. * This is the COBOL equivalent of a subroutine call - and you specify both * entry and exit points yourself! ALTER SKIP TO PROCEED TO ELIMINATE-1. * The above statement is a real goodie - it changes the GO TO END-FUNC below * to GO TO ELIMINATE-1. PERFORM SOLVE THROUGH END-SOLVE MOVE LAST-X TO ROOT-2. ALTER SKIP TO PROCEED TO ELIMINATE-2. PERFORM SOLVE THROUGH END-SOLVE. DISPLAY "NO MORE ROOTS". STOP RUN. SOLVE. MOVE -1 TO OLD-X MOVE ALL ZEROES TO LAST-X, ITERATIONS. LOOP. MOVE OLD-X TO X PERFORM COMPUTE-FUNCTION THROUGH END-FUNC MOVE Y TO Y1. MOVE LAST-X TO X PERFORM COMPUTE-FUNCTION THROUGH END-FUNC MOVE Y TO Y2. IF OLD-X - LAST-X IS LESS THAN EPS AND GREATER THAN - EPS GO TO END-SOLVE. SUBTRACT OLD-X FROM LAST-X GIVING TEMP. SUBTRACT Y1 FROM Y2 GIVING TEMP2. MULTIPLY Y2 BY TEMP DIVIDE TEMP2 INTO TEMP. SUBTRACT TEMP FROM LAST-X GIVING NEW-X. MOVE LAST-X TO OLD-X MOVE NEW-X TO LAST-X. ADD 1 TO ITERATIONS. * This way of writing aritmetical statements is peculiar to COBOL. * You are permitted to write COMPUTE NEW-X = LAST-X - * ( LAST-X - OLD-X ) / ( Y2 - Y1 ) instead, but that's no sport! IF ITERATIONS IS GREATER THAN 20 DISPLAY "NO ROOT FOUND" STOP RUN. IF Y2 IS LESS THAN - EPS OR GREATER THAN EPS GO TO LOOP. END-SOLVE. MOVE LAST-X TO EDITED-NBR DISPLAY "X=", EDITED-NBR. * Numbers are formatted for output by moving them to special "edited" * variabels like EDITED-NBR.These variables are defined by special * PICTURE clauses in the DATA DIVISION (if that makes you any wiser, * you don't need to read the rest) COMPUTE-FUNCTION. MULTIPLY 7 BY X GIVING Y SUBTRACT 1 FROM Y MULTIPLY X BY Y MULTIPLY 9 BY Y. SUBTRACT 7 FROM Y MULTIPLY X BY Y ADD 1 TO Y. SKIP. GO TO END-FUNC. * This statement is altered twice: first to GO TO ELIMINATE-1 * and then to GO TO ELIMINATE-2. This self-modifying feature makes it * possible to write very elegant programs and is a real challenge to * any creative programmer. ELIMINATE-2. SUBTRACT ROOT-2 FROM X GIVING TEMP DIVIDE TEMP INTO Y. ELIMINATE-1. SUBTRACT ROOT-1 FROM X GIVING TEMP DIVIDE TEMP INTO Y. END-FUNC. EXIT.
Auswege: Impressum, Haftungsausschluß, Datenschutz,
Humor im Internet,
Links: Imprint, Humor on the Internet, my homepage.
$Id: cobol.html 1.2 1995/12/12 01:26:29 thb Exp thb $