Code Comments
Programming Forum and web based access to our favorite programming groups.I'm new to Cobol. I would like to know if it is ansi compliant don't put the period after an END-IF. For example wich of the two following snip code are more standard. 1) IF O = "+" THEN COMPUTE C=A+B END-IF 2) IF O = "+" THEN COMPUTE C=A+B END-IF. Thanks, G.
Post Follow-up to this message"GLari" <turbolenceATgmailDOTcom> wrote in message news:42a6ad66$1_1@news.bluewin.ch... > I'm new to Cobol. I would like to know if it is ansi compliant don't put > the period after an END-IF. For example wich of the two following snip > code are more standard. > > 1) > IF O = "+" THEN > COMPUTE C=A+B > END-IF > > 2) > IF O = "+" THEN > COMPUTE C=A+B > END-IF. > It is really a matter of opinion. Mine is as follows: "Don't mix coding styles. The days of full stops/periods as part of COBOL logic are gone. They caused endless heartbreak , wailing, and gnashing of teeth, particularly on barrel printers which did not always print them clearly. We have scope delimiters; they were added for a purpose, by people who understood the need for them. Use them, and relegate the full stop/period to it's syntactical job of delineating the end of a paragraph or section. (preceding a procedure-name)." Number 1 gets my vote (at least as far as full stops/periods go...I have some other reservations about it which I won't go into here...) Pete.
Post Follow-up to this messageXref: newsfeed-west.nntpserver.com comp.lang.cobol:114302 > "Don't mix coding styles. The days of full stops/periods as part of COBOL > logic are gone. They caused endless heartbreak , wailing, and gnashing of > teeth, particularly on barrel printers which did not always print them > clearly. We have scope delimiters; they were added for a purpose, by peopl e > who understood the need for them. Use them, and relegate the full > stop/period to it's syntactical job of delineating the end of a paragraph > or section. (preceding a procedure-name)." > So if I understand clearly, I should avoid this: IF O = "+" PERFORM COMPUTE-DISPLAY-ADD. IF O = "*" PERFORM COMPUTE-DISPLAY-MUL. Sorry, but I don't understand why. G.
Post Follow-up to this message"GLari" <turbolenceATgmailDOTcom> wrote in message news:42a6b6bc_2@news.bluewin.ch... COBOL of people paragraph > > So if I understand clearly, I should avoid this: > > IF O = "+" > PERFORM COMPUTE-DISPLAY-ADD. > IF O = "*" > PERFORM COMPUTE-DISPLAY-MUL. > > Sorry, but I don't understand why. > G. > The reasons are long, involved, historic, and arguable. If you WANT to code that way, do so. It is a choice. Here's how it would be done with scope delimiters... IF O = "+" PERFORM COMPUTE-DISPLAY-ADD END-IF IF O = "*" PERFORM COMPUTE-DISPLAY-MUL END-IF ....more code here... It is immediately obvious what the scope of each IF is. It is with the full stop/periods, too, if you can see them.... I know it is hard to believe this, but there are occasions when COBOL Programmers get dragged into work in the middle of the night to fix something critical that has crashed. It might not even be you... Make things as obvious as you can. Someone will bless your name for it and the word will get round that you are a dab hand at this COBOL code stuff... Just for completion, here is how I would code it...(If I worked on your site; it isn't really how I'd code it for my personal use...) (I hope you have validated the input operands BEFORE doing this .... :-) (Check out the COBOL 'class' test...it determines the 'class' (alphabetic, alphanumeric, or numeric,) of a field). Also, try to use meaningful names for data. Your procedure names are great, but 'O' is not really an adequate dataname for an arithmetic operator... :-)) EVALUATE O WHEN "+" PERFORM COMPUTE-DISPLAY-ADD WHEN "-" PERFORM COMPUTE-DISPLAY-SUB WHEN "/" PERFORM COMPUTE-DISPLAY-DIV WHEN "-" PERFORM COMPUTE-DISPLAY-MUL WHEN OTHER PERFORM NOTIFY-INVALID-ARITHMETIC-OPERATOR END-EVALUATE Again, the scope delimiters (EVALUATE...END-EVALUATE) show very clearly what the scope of the EVALUATE statement is. We used full stops in the old days because we had no choice. Now we do have a choice, and I, for one, don't use full stops to delineate logic. But some people do. It isn't 'wrong'; it is a choice. Pete.
Post Follow-up to this messageI realised, after sending, that the procedure name: NOTIFY-INVALID-ARITHMETIC-OPERATOR is more than 30 characters long and thus violates the original COBOL standard. Some compilers will truncate it, others will accept it as written, some others will flag it as an error. Change it to whatever you like that is less than 31 characters. I suggest: NOTIFY-INVALID-ARITH-OPERATOR Pete. TOP POST nothing new below. "Pete Dashwood" <dashwood@enternet.co.nz> wrote in message news:3gnv8dFdel05U1@individual.net... > > "GLari" <turbolenceATgmailDOTcom> wrote in message > news:42a6b6bc_2@news.bluewin.ch... > COBOL > of > people > paragraph > The reasons are long, involved, historic, and arguable. > > If you WANT to code that way, do so. It is a choice. > > Here's how it would be done with scope delimiters... > IF O = "+" > PERFORM COMPUTE-DISPLAY-ADD > END-IF > IF O = "*" > PERFORM COMPUTE-DISPLAY-MUL > END-IF > ....more code here... > > It is immediately obvious what the scope of each IF is. It is with the full > stop/periods, too, if you can see them.... I know it is hard to believe > this, but there are occasions when COBOL Programmers get dragged into work > in the middle of the night to fix something critical that has crashed. It > might not even be you... Make things as obvious as you can. Someone will > bless your name for it and the word will get round that you are a dab hand > at this COBOL code stuff... > > Just for completion, here is how I would code it...(If I worked on your > site; it isn't really how I'd code it for my personal use...) > > (I hope you have validated the input operands BEFORE doing this .... :-) > (Check out the COBOL 'class' test...it determines the 'class' (alphabetic, > alphanumeric, or numeric,) of a field). Also, try to use meaningful names > for data. Your procedure names are great, but 'O' is not really an adequate > dataname for an arithmetic operator... :-)) > > EVALUATE O > WHEN "+" > PERFORM COMPUTE-DISPLAY-ADD > WHEN "-" > PERFORM COMPUTE-DISPLAY-SUB > WHEN "/" > PERFORM COMPUTE-DISPLAY-DIV > WHEN "-" > PERFORM COMPUTE-DISPLAY-MUL > WHEN OTHER > PERFORM NOTIFY-INVALID-ARITHMETIC-OPERATOR > END-EVALUATE > > Again, the scope delimiters (EVALUATE...END-EVALUATE) show very clearly what > the scope of the EVALUATE statement is. > > We used full stops in the old days because we had no choice. Now we do have > a choice, and I, for one, don't use full stops to delineate logic. > > But some people do. It isn't 'wrong'; it is a choice. > > Pete. > > > > >
Post Follow-up to this message> Here's how it would be done with scope delimiters... > IF O = "+" > PERFORM COMPUTE-DISPLAY-ADD > END-IF > IF O = "*" > PERFORM COMPUTE-DISPLAY-MUL > END-IF I don't understand why the period solution is more error prone. Isn't the scope of each if limited to only _one statement_? If the language would permit more statement inside the if scope I would be agree to use a well visible keyword to mark where the scope end. But if the scope is always one istruction I don't understand what is the difference between the two ways. > Just for completion, here is how I would code it...(If I worked on your > site; it isn't really how I'd code it for my personal use...) Thanks for your solution. Actually I'm trying to understand the "if" keyword so my example is completely artificial but I expect some more convenient construct (case of) to manage problem like this. Anyway it is usefull to me see what I will meet in some days.... Thanks again, Gianmaria
Post Follow-up to this messageIn article <42a6ad66$1_1@news.bluewin.ch>, GLari <turbolenceATgmailDOTcom> wrote: >I'm new to Cobol. I would like to know if it is ansi compliant don't put >the period after an END-IF. That depends, I believe, on where in the paragraph the END-IF is located. DD
Post Follow-up to this message> If the language would permit more statement inside the if scope I would > be agree to use a well visible keyword to mark where the scope end. But > if the scope is always one istruction I don't understand what is the > difference between the two ways. Sorry I understood. Cobol permits more statement in the if scope!! Thank for the help. P.S. Of course now is clear why use end-if.
Post Follow-up to this messageIn article <42a6b6bc_2@news.bluewin.ch>, GLari <turbolenceATgmailDOTcom> wrote: > > So if I understand clearly, I should avoid this: > > IF O = "+" > PERFORM COMPUTE-DISPLAY-ADD. > IF O = "*" > PERFORM COMPUTE-DISPLAY-MUL. > > Sorry, but I don't understand why. > G. That would be wise to avoid. The full-stop period as a scope delimiter is a "END-EVERYTHING" statement. An nuclear scope delimiter as it were. Far better to use the constructs available for the last several decades and write: If O = "+" Perform Compute-Display-Add End-If If O = "*" Perform compute-Display-Mul End-If I'm sure you will hear from those who will say something to the effect of 'my grandpappy used full-stops, my pappy used full-stops, full-stops were good enough for them, they are good enough for me'. Just know they are stuck in an age of disco music and unstructured code. Quite possibly they don't know any better.
Post Follow-up to this messageIn article <42a6ccc4$1_1@news.bluewin.ch>, GLari <turbolenceATgmailDOTcom> wrote: > > I don't understand why the period solution is more error prone. Isn't > the scope of each if limited to only _one statement_? That is a common misconception. The END-* delimiters apply only to the last statement of type '*' and the compiler will enforce this. The '.' delimiter will apply to ALL scopes currently active. So you could do something like this: If condition-1 lots-of-stuff more-stuff several-hundered-lines
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.