Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
COBOL code with GO TOs
Goto page Previous  1, 2
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 684
Location: Whitby, ON, Canada

PostPosted: Fri Apr 15, 2011 3:49 am    Post subject:
Reply with quote

Bill Woodger wrote:
don.leahy wrote:
Congratulations Bill. This is the first GO TO discussion thread in the history of the internet that didn't deteriorate into a holy war.

Well, not yet anyway. icon_evil.gif


Thanks... is the last a potential you are worried about, or a threat? :-)

No. 11 for your mainframe wars?
You're right about that. I don't know how I missed that one.

If I wanted to start a holy war I would say something like: "GO TOs are for amateurs who don't know how to think logically". icon_wink.gif

The discussion group comp.lang.cobol is rife with pointless never ending discussions about sections vs paragraphs, OO vs structured, mainframe vs non-mainframe etc. I don't hang out there any more.
Back to top
View user's profile Send private message

Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Fri Apr 15, 2011 3:52 am    Post subject:
Reply with quote

Verbs/instructions/statements or whatever the language calls it arent inherently good or bad. Their use on the other hand .....
Programs are coded well or badly, as I think most people would agree.
I have seen and had to maintain some garbage "perform-rich, goto-free " programs and some excellent "branch-fests" [including self modifying elements ] - the use or absence of certain verbs/instructions do not determine structure or spaghetti

While performance now-a-days is less of an issue, when designing a program, than it once was; when it is ..it really is. But it should still possible to write good, maintainable code.
A good programmer should have the skills to know how to design and code an appropriate solution, including well named variables, good comments [MVC ABC,A1 move A1 to ABC ....WOW!- helpful!]

.... must agree with the literals in PROCEDURE DIVISION thing though
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 684
Location: Whitby, ON, Canada

PostPosted: Fri Apr 15, 2011 3:57 am    Post subject:
Reply with quote

Peter Nancollis wrote:

.... must agree with the literals in PROCEDURE DIVISION thing though


So do I, as long as it doesn't degenerate into:

Code:
05 WS-ONE  PIC S9(2) COMP  VALUE +2.
. . .
ADD WS-ONE to WS-COUNT
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Fri Apr 15, 2011 4:32 am    Post subject:
Reply with quote

don.leahy wrote:
Peter Nancollis wrote:

.... must agree with the literals in PROCEDURE DIVISION thing though


So do I, as long as it doesn't degenerate into:

Code:
05 WS-ONE  PIC S9(2) COMP  VALUE +2.
. . .
ADD WS-ONE to WS-COUNT


Shucks, yes. And the one without a value clause at all (it can't be looping, look, I add one to it!). And make it unsigned usage display.

What I like to do is to make a seperation. If it is something that is just a number, like adding 1 to control a loop, I use a numeric literal. If it is something that is constant, but has a meaning, and just happens to be a number that is known at the time you write the program, I defined it in WS. Then the things I need are in the XREF, without having to ignore countless (if the literal is 1) irrelevant references. I will even define multiple "constants" with the same value, if necessary, but the name I give each will describe what the thing is about.

I have to admit, the moron can turn it into chaos.

Hey, we're slipping off-topic, and I'm helping!

The thing is, we're not really, because it is about good code vs bad, rather than to go, or not to go.

Does an example of bad code, posted in this forum, necessarily indicate a bad programmer? Or a future bad programmer? I'd have loved to have access to the amount of knowledge here as I was starting out. I wouldn't have liked to be told to "get a different career", however. OK, if I then ask the same dumb question five times in different guises, blow me away.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Fri Apr 15, 2011 4:54 am    Post subject:
Reply with quote

Peter Nancollis wrote:
Verbs/instructions/statements or whatever the language calls it arent inherently good or bad. Their use on the other hand .....
Programs are coded well or badly, as I think most people would agree.
I have seen and had to maintain some garbage "perform-rich, goto-free " programs and some excellent "branch-fests" [including self modifying elements ] - the use or absence of certain verbs/instructions do not determine structure or spaghetti

While performance now-a-days is less of an issue, when designing a program, than it once was; when it is ..it really is. But it should still possible to write good, maintainable code.
A good programmer should have the skills to know how to design and code an appropriate solution, including well named variables, good comments [MVC ABC,A1 move A1 to ABC ....WOW!- helpful!]

.... must agree with the literals in PROCEDURE DIVISION thing though


I agree. It's the logic, stupid, to misquote someone or other. Or misquote an alleged quote, or whatever.

Performance and Comments. Two more subjects for topics...

I have to say, Peter, when I see your "avatar" I always think of the caption, said through gritted teeth, "Tell. Me. Again. Exactly who dropped the object-deck down there?"
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2230
Location: Hampshire, UK

PostPosted: Fri Apr 15, 2011 9:46 am    Post subject:
Reply with quote

Quote:
people starting out


Unfortuntely I get the impression that they will not be reading this thread because:
    they did not start it
    they do not understand it
    their code is correct
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Fri Apr 15, 2011 12:10 pm    Post subject:
Reply with quote

Nic Clouston wrote:
Quote:
people starting out


Unfortuntely I get the impression that they will not be reading this thread because:
    they did not start it
    they do not understand it
    their code is correct


Not so sure that we've covered anything particularly difficult so that it can't be understood. If there is anything unclear, or obscure, to anyone, feel free to ask.

Do you mean they think their code is correct?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Fri Apr 15, 2011 12:15 pm    Post subject:
Reply with quote

Best inovation:

end construct
expansion of file-status


things that should be removed from cobol:

declaratives.

read .... at end
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Sat Apr 16, 2011 4:32 am    Post subject: Reply to: GO TOs
Reply with quote

OK, this is winding down now. Further comments welcome, but over the weekend I'll try to summarise what has been contributed so far.

Thanks everyone. I enjoyed it.

Now, the next is really not for those with weak hearts. Novices, do not read beyond this point.

OK, I'm sure everyone has one of these, but if you've lost yours...

I apologise, I don't have access to a m/f so I can't test it. Used to work. Optimising off (might not be necessary, I never ran this through an optimiser. Should be OK, but safer off). Possibly CMPR2 but I dont' think so. From memory, but updated for "COBOL II". Sorry if it doesn't work. I've been poring over it, and I think I got everything.


Code:

01  A1-FG PIC X VALUE SPACE.
01  B1-FG PIC X VALUE SPACE.
01  C1-FG PIC X VALUE SPACE.


    PERFORM A
    IF A1-FG EQUAL TO "Y"
        DISPLAY "DO"
        GO TO G6
    END-IF
    .
G1.
    PERFORM B
    IF B1-FG EQUAL TO "Y"
        DISPLAY "DOO"
        GO TO G5
    END-IF
    .
G2.
    PERFORM C
    IF C1-FG EQUAL TO "Y"
        DISPLAY "IN DEEP"
        GO TO G4
    END-IF
    .
G3.


OK, so far not too bad. Some GO TOs, some paragraphs that look suspicious, but straight-forward logic?


Code:

G3.
    GO TO C5
    .
G4.
    GO TO B5
    .
G5.
    GO TO A5
    .
G6.
    MOVE +11 TO RETURN-CODE
    STOP RUN
    .



What the heck is that? As my son would say, quoting the film "Robots".

Code:



A SECTION.
    GO TO G1
    .
A5.
    MOVE "Y" TO A1-FG
    .
A9.
    EXIT.
B SECTION.
    GO TO G2
    .
B5.
    MOVE "Y" TO B1-FG
    .
B9.
    EXIT.
C SECTION.
    GO TO G3
    .
C5.
    MOVE "Y" TO C1-FG
    .
C9.
    EXIT.


Well, goodnes, gracious me. Ponder. Go on, copy-and-paste. Compile. Fingers crossed. Run it.

And no, I don't code my programs like that :-)

But you can get the effect through coding error (which gave me the idea for the program). Kind of like the one Dick mentioned in the original thread.
Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Sat Apr 16, 2011 4:58 am    Post subject:
Reply with quote

I will see your :
Code:


05 WS-ONE  PIC S9(2) COMP  VALUE +2.
. . .
ADD WS-ONE to WS-COUNT


and raise you a [yes it has run in prod -sigh! ]

Code:

           PERFORM X100-INCREMENT.
....
       X100-INCREMENT SECTION.
       X110-ADD-ONE.                                                           
           ADD 1 TO WS10-COUNTER.                                     
       X199-EXIT.                                                               
           EXIT. 


When I did COBOL, though [and No, its not my code - too structured : o) ] ...In-line performs (and lots lots more that has followed) werent even a twinkle in the compiler's eye

Now if we are collecting topics for venting spleens.... can I add Nested IFs
[at the risk of re-ignition ... more of a maint problem than GOTOs <g,d,r> ]
ttfn
Back to top
View user's profile Send private message
Peter Nancollis

New User


Joined: 15 Mar 2011
Posts: 47
Location: UK

PostPosted: Sat Apr 16, 2011 5:04 am    Post subject:
Reply with quote

Quote:

Do you mean they think their code is correct?

If the compile/lked ends 0000/0000 doesnt that mean all is well?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Sun Apr 17, 2011 5:18 am    Post subject:
Reply with quote

Quote:

Compile. Fingers crossed. Run it.


Compiles, and works. I'd love to watch it in a debugger.

Peter, I re-raise. You forgot the comments naming the section, listing where it is performed from, listing what it performs, describing what it does. All in a "comment box" which makes sure you don't see a single line of code when you scroll to the section name. And then, of course, a comment for each line of the code. And at least 40% of the comments should be wrong.

z 7 7#all/*#del *#z 1 *#all

Mmmm... Comments next, or Nesting?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Sun Apr 17, 2011 2:05 pm    Post subject:
Reply with quote

In summary:

There is good code and bad code. Language constructs are not inherently good or bad, they can be used well or poorly.

If you use GO TO, don't do stupid things that are only asking for trouble (like GO TO out of a para/section which is being PERFORMed).

If you avoid using GO TO, don't make the situation as bad going the other way. If it is clearer and more appropriate and avoids more complicated code, why not use GO TO?

Generally, we do avoid/limit use of GO TO.

Thanks to (first come, first served), GuyC, Bill O'Boyle, Akatsukami, don.leahy, prino, dbzTHEdinosauer, Ronald Burr, Peter Nancollis, Nic Clouston.
Back to top
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Tue Apr 19, 2011 2:40 pm    Post subject:
Reply with quote

@Bill Woodger

Morning Sir !

I'm very pleased when i read your diskussion-blog about using a GOTO.

As i wrote in another topic, my narrow view of a matter is, that experienced programmers, with a minimum of intellect do not need to code a GOTO.

For my own, i do not code a "Branch-Inctruction" in my assembler programms. I use the old IBM Structured Makros wherever i can.

I appreciate this diskussion. I'm allways trying to learn something from such an exchange of experience. Even though i don't know if it's worth for me to do so for the last few years i have to work.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7312

PostPosted: Tue Apr 19, 2011 3:06 pm    Post subject: Reply to: GO TOs
Reply with quote

Thank you, UmeySam, I was hoping to attract you to the discussion after your previous comment.

As you have seen from the discussion, mostly experienced people avoid GO TOs and definitely only use them with strict criteria.

People with less experience will not, in my mind, be helped simply by telling them what pieces of language to use, or not use, as this does not in itself, necessarily, of necessity, lead to good, maintainable, code.

As you are one of the more "hard line" who have commented, perhaps you can help out by descring how you deal with the "nesting" issues in the other discussion?

Thanks again.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to handle NULL in COBOL program bhaskar_kanteti COBOL Programming 8 Mon Oct 07, 2019 3:54 pm
This topic is locked: you cannot edit posts or make replies. COBOL/CICS with real time MQ Series u... BPranav CICS 2 Mon Sep 16, 2019 9:19 pm
This topic is locked: you cannot edit posts or make replies. Compare two files logic in COBOL Nishant Singhal COBOL Programming 4 Sun Aug 25, 2019 2:25 am
No new posts proc step return code to override in ... Aaryaa JCL & VSAM 3 Tue Aug 20, 2019 4:32 pm
This topic is locked: you cannot edit posts or make replies. Upgrade to Enterprise COBOL 6 JPVRoff COBOL Programming 4 Thu Aug 01, 2019 7:21 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us