From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,FROM_WORDY, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5d71,d275ffeffdf83655 X-Google-Attributes: gidf5d71,public X-Google-Thread: 146b77,d275ffeffdf83655 X-Google-Attributes: gid146b77,public X-Google-Thread: 109fba,d275ffeffdf83655 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,d275ffeffdf83655 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: COBOL/Top-Down prog'g (was: Ada vs C++ vs Java) Date: 1999/01/24 Message-ID: <78i6m0$505$2@plug.news.pipex.net>#1/1 X-Deja-AN: 436727944 References: <369C1F31.AE5AF7EF@concentric.net> <369CBD05.79D0@telusplanet.net> <369CBDA8.D3673C68@pwfl.com> <77np3q$e6h$1@nnrp1.dejanews.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom) Newsgroups: comp.lang.ada,comp.lang.c++,comp.vxworks,comp.lang.java Date: 1999-01-24T00:00:00+00:00 List-Id: Consider the following Ada equivalent of Robert's COBOL example: procedure Send_Bill; procedure Record_Credit; ... procedure Process_Balance is ... begin ... if Balance < 0 then Send_Bill; else Record_Credit; end if; ... end Process_Balance; ... procedure Send_Bill is ... begin ... end Send_Bill; procedure Record_Credit is ... begin ... end Record_Credit; Hopefully this illustrates Robert's point that declaring lots of procedures in Ada has more code overhead. But, it also illustrates that the lower-level (more 'refined') code can be placed after the higher level that refers to it: with the catch of having to include forward declarations. I hope this example also shows what a really clear way of programming this 'stepwise refinement' can be. Personally, I would recommend this as a good style of programming in both Ada and COBOL, in most circumstances. (Of course, like everything in life, you can overdo it!) Consider the following fragment of Ada code if Balance < 0 then if Alternative_Credit + Balance < 0 then if Husband.Sister.Uncle.Niece not in Family.Friends then if Day = Tuesday then if Mood = Really_Bad then Send_Stinking_Credit_Letter; else Send_Normal_Credit_Letter; end if; else Schedule_Credit_Letter; end if; else Slip_In_A_Loan_On_The_Quiet((100.00-Balance); end if; else Send_Warning_Letter; Schedule_Emergency_Loan(-Balance); end if; else Record_Credit(Balance); end if; This is terrible spaghetti code. And not a 'goto' in sight! Now consider a COBOL 77 equivalent: PROCESS-BALANCE. if BALANCE is positive, perform POSITIVE-BALANCE. if BALANCE is negative, perform NEGATIVE-BALANCE. note if BALANCE is zero, no action taken. POSITIVE-BALANCE. move BALANCE to CREDIT-AMOUNT. perform RECORD-CREDIT. NEGATIVE-BALANCE. subtract BALANCE from 0 giving DEFICIT. if CREDIT-AVAILABLE is less than DEFICIT, perform INSUFFICIENT-CREDIT, else perform ENOUGH-CREDIT. INSUFFICIENT-CREDIT. if STATUS of NIECE of UNCLE of SISTER of HUSBAND = 'FRIEND', perform FRIENDLY-LOAN, else perform NASTY-LETTER-TIME. FRIENDLY-LOAN. add 100 to DEFICIT giving LOAN-AMOUNT. perform SNEAK-A-QUICK-LOAN-WHILE-NOBODY-LOOKING. NASTY-LETTER-TIME. if MOOD = 'VBAD', move 'BOTH LEGS' to WHICH-BONE, else move 'A FINGER ' to WHICH-BONE. move DEFICIT to LETTER-AMOUNT. if DAY = 'TUE', perform NASTY-LETTER-TUESDAY, else perform NASTY-LETTER-NON-TUESDAY. NASTY-LETTER-TUESDAY. perform SEND-NASTY-LETTER. NASTY-LETTER-NON-TUESDAY. perform SCHEDULE-NASTY-LETTER. ENOUGH-CREDIT. move DEFICIT to LOAN-AMOUNT. perform ARRANGE-EMERGENCY-LOAN. perform SEND-WARNING-LETTER. I think this example makes two things stand out: the Ada example is obviously more compact, but the COBOL, with its many self-documenting labels (and extra variables), is much more readable code. You can imagine an Ada equivalent derived from the above COBOL, and you can also image a possible C version of the original Ada nested 'if's, more compact still, and even less readable. I hope I have gone a little way towards enlightening those of you who may have scoffed at Robert's assertion that writing COBOL in a 'COBOLish' manner is better than trying to write COBOL in 'Pascalese', and that COBOL has some better features. There are definitely some advantages to the COBOL language - when the code is written well, and in COBOL's native style - over other (supposedly more advanced) languages. There are also, without doubt, problems: having to pass parameters in global variables; the lack of a (visual) 'stopper' at the end of a procedure; the lack of structured constructs (a problem until COBOL 90). The 'ALTER' verb was a total classic. Nobody ever used it, fortunately (did they?). I think the fact that Pascal, Ada, C, and other block-structured languages allow a mixture of styles - nesting structures directly, and breaking code down into named constituent parts (functions/procedures) - means that the programmer is given the ability to choose a good compromise between the compactness of one style and the clarity of the other. As ever, it is up to the skill of the programmer to actually choose a good compromise. Finally, consider a one-line C declaration for the factorial function: int fact(int i) { if (i < 0) halt(9) else return i < 2? 1 : i * fact(i-1); }; C can be a very neat language, sometimes. ------------------------------------------- Nick Roberts ------------------------------------------- robert_dewar@my-dejanews.com wrote in message <77np3q$e6h$1@nnrp1.dejanews.com>... [about COBOL style of coding]