For Programmers: Free Programming Magazines  


Home > Archive > Cobol > May 2004 > Use CONTINUE not NEXT SENTENCE was Re: Avoiding Logic Error?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Use CONTINUE not NEXT SENTENCE was Re: Avoiding Logic Error?
Clark F. Morris, Jr.

2004-05-14, 8:30 am

Hugh Candlin wrote:
> William Bub <fathafluff@hotmail.com> wrote in message news:rgWoc.249467$e17.171934@twister.nyroc.rr.com...
>
>
>
> The coding style that I use was adopted to help avoid such logic errors
> (although that was not the main reason).
>
> I use the ELSE clause in every IF statement as a reminder to myself
> to consider and identify what needs to be executed within both logic paths.
>
> If I have no need for a specific imperative statement, I use NEXT SENTENCE,
> either before or after the ELSE, as appropriate.
>
> I also use blank lines and column spacing to help with readability.
>
> Using that style, your example would be coded as
>
> PROCESS-PARAG.
> IF REC-TYPE = 1
> PERFORM EDIT-REC
> IF EDIT-ERR = 'Y'
> PERFORM HANDLE-ERROR
> ELSE
> NEXT SENTENCE
> ELSE
> NEXT SENTENCE.
>
> PERFORM MORESTUFF.
>
>
>

If you want to avoid future problems, REPLACE "NEXT SENTENCE" with
"CONTINUE" in your programs. This will work whether you use periods or
scope terminators and will allow you to move from using periods to using
scope terminators without getting nasty surprises.

Robert Jones

2004-05-14, 4:30 pm

"Clark F. Morris, Jr." <cfmtech@istar.ca> wrote in message news:<c829rg$rjb$1@news.eusc.inter.net>...

message snipped

> If you want to avoid future problems, REPLACE "NEXT SENTENCE" with
> "CONTINUE" in your programs. This will work whether you use periods or
> scope terminators and will allow you to move from using periods to using
> scope terminators without getting nasty surprises.


NEXT SENTENCE and CONTINUE are not exactly equivalent, I agree that
using CONTINUE is preferable, but though the examples shown so far are
amenable to a simple replace, this is certainly not always the case
and care must be taken when converting existing programs to use
CONTINUE instead of NEXT SENTENCE.

I would unhesitatingly prefer CONTINUE in a new program, but would
have to use my judgement about whether to change the style of an old
program when just making (relatively) minor changes to the rest of the
logic.

Robert
Donald Tees

2004-05-14, 4:30 pm

Robert Jones wrote:
> "Clark F. Morris, Jr." <cfmtech@istar.ca> wrote in message news:<c829rg$rjb$1@news.eusc.inter.net>...
>
> message snipped
>
>
>
>
> NEXT SENTENCE and CONTINUE are not exactly equivalent, I agree that
> using CONTINUE is preferable, but though the examples shown so far are
> amenable to a simple replace, this is certainly not always the case
> and care must be taken when converting existing programs to use
> CONTINUE instead of NEXT SENTENCE.
>
> I would unhesitatingly prefer CONTINUE in a new program, but would
> have to use my judgement about whether to change the style of an old
> program when just making (relatively) minor changes to the rest of the
> logic.
>
> Robert




I do not think continue should be used as a substitute for "next
sentence" at all. People should code "continue" where they want a
no-op, and "next sentence" when they want to exit from the sentence.
They do very different things.

It strikes me as odd the "exit paragraph" is lauded as such a vast
improvement in the language by the same people that want to remove "next
sentence". They both do exactly the same thing. They "go to" the end
of a particular section of code.

Would it make it better if we put in an "exit sentence" instead of a
"next sentence", and perhaps and "end sentence" instead of a simple
period? The sentence is a basic unit of code in Cobol, and always has
been. It needs both a terminator, and an exit mechanism. We have both.

If people really wish to make every sentence a complete paragraph,
running on and on for 20 to 30 lines, I suppose that is their
perogative. It can be done, just as run-on sentences can be written in
other languages. I do not see it as an improved style, however. I think
it makes code less readable, not more readable.

Donald


Donald

Howard Brazee

2004-05-14, 5:30 pm


On 14-May-2004, Donald Tees <donald_tees@sympatico.ca> wrote:

> It strikes me as odd the "exit paragraph" is lauded as such a vast
> improvement in the language by the same people that want to remove "next
> sentence". They both do exactly the same thing. They "go to" the end
> of a particular section of code.


One difference is the end of paragraph is more obvious and less likely to be
overlooked than the end of sentence.

The other difference is that EXIT PARAGAPH will get rid of the last argument
that has any substance to it - in favor of exit paragraphs. It will be worth
it to win this argument.
LX-i

2004-05-14, 10:30 pm

Robert Jones wrote:

> I would unhesitatingly prefer CONTINUE in a new program, but would
> have to use my judgement about whether to change the style of an old
> program when just making (relatively) minor changes to the rest of the
> logic.


If you were only making minor changes, you probably wouldn't be adding
scope delimiters where there were none, so the continue vs. next
sentence thing wouldn't come up. :)


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

LX-i

2004-05-14, 10:30 pm

Howard Brazee wrote:

> The other difference is that EXIT PARAGAPH will get rid of the last argument
> that has any substance to it - in favor of exit paragraphs. It will be worth
> it to win this argument.


Hear hear - add mine as another "yea" vote...

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~ / \ / ~ Live from Montgomery, AL! ~
~ / \/ o ~ ~
~ / /\ - | ~ LXi0007@Netscape.net ~
~ _____ / \ | ~ http://www.knology.net/~mopsmom/daniel ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~ I do not read e-mail at the above address ~
~ Please see website if you wish to contact me privately ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~

Richard

2004-05-15, 1:30 am

Donald Tees <donald_tees@sympatico.ca> wrote


In all cases where NEXT SENTENCE has been correctly used, ie there are
no END-IFs in the same scope, the replacing of NEXT SENTENCE is
entirely safe and the results will be identical.

The difference between NEXT SENTENCE and CONTINUE only occurs where
NEXT SENTENCE and END-IF are together in one sentence.

If there are any cases where the replacement would cause a difference
then the program is a bugtrap and should be ceremonially burnt.
[color=darkred]
> Would it make it better if we put in an "exit sentence" instead of a
> "next sentence",


What would the difference be between these ?

> If people really wish to make every sentence a complete paragraph,
> running on and on for 20 to 30 lines, I suppose that is their
> perogative. It can be done, just as run-on sentences can be written in
> other languages. I do not see it as an improved style, however. I think
> it makes code less readable, not more readable.


Do you have conditional statements where the body of the action is
several statements ? These "run on and on" without a terminator.

Whatever is 'more readable' is 'what you are used to'. I am used to
reading code with a single full stop at the end of the paragraph, so I
find that more readable. In fact my editor highlights full stops with
a red background so I find them jarring and remove them wherever
possible.
William M. Klein

2004-05-15, 1:30 am


"Richard" <riplin@Azonic.co.nz> wrote in message
news:217e491a.0405142001.5393a38f@posting.google.com...
> Donald Tees <donald_tees@sympatico.ca> wrote
>
>
> In all cases where NEXT SENTENCE has been correctly used, ie there are
> no END-IFs in the same scope, the replacing of NEXT SENTENCE is
> entirely safe and the results will be identical.
>


Can you define "correctly used" for me?

The following FULLY conforming '85 Standard code shows the REAL and "meaningful"
difference between NEXT SENTENCE and CONTINUE

IF A = "A"
If B = "B"
Next Sentence
Else
Continue
Else
Display "A not = 'A' "
End-If
Display "B not = 'B' "
Richard

2004-05-15, 4:30 pm

"William M. Klein" <wmklein@nospam.netcom.com> wrote

> Now, I "snipped" some of the original note and I would agree that this
> programming logic may be "error-prone" - but I question definitions that state
> that the "Next Sentence" is "incorrectly used" - as the code does EXACTLY what
> it was intended to do.


I know that you have this particular interpretation. The standard
specifies by its syntax that NEXT SENTENCE and END-IF cannot be in the
same IF statement. The committee have clarified that the syntax has
not disallowed your contrived use of nesting IFs to bypass the
restriction.

You assert that this contrived usage was _intended_ to be allowed,
while I continue to consider that it has only been allowed by
inadequate prohibition.

Who'da thunk that anyone would _want_ to create such obscure and bug
prone code.
Joe Zitzelberger

2004-05-15, 9:30 pm

In article <Of9pc.81081$FH5.1858642@news20.bellglobal.com>,
Donald Tees <donald_tees@sympatico.ca> wrote:

> Robert Jones wrote:
>
>
>
> I do not think continue should be used as a substitute for "next
> sentence" at all. People should code "continue" where they want a
> no-op, and "next sentence" when they want to exit from the sentence.
> They do very different things.
>
> It strikes me as odd the "exit paragraph" is lauded as such a vast
> improvement in the language by the same people that want to remove "next
> sentence". They both do exactly the same thing. They "go to" the end
> of a particular section of code.
>
> Would it make it better if we put in an "exit sentence" instead of a
> "next sentence", and perhaps and "end sentence" instead of a simple
> period? The sentence is a basic unit of code in Cobol, and always has
> been. It needs both a terminator, and an exit mechanism. We have both.
>
> If people really wish to make every sentence a complete paragraph,
> running on and on for 20 to 30 lines, I suppose that is their
> perogative. It can be done, just as run-on sentences can be written in
> other languages. I do not see it as an improved style, however. I think
> it makes code less readable, not more readable.
>
> Donald
>
>
> Donald
>


I really have to disagree with you here. The sentence is completely
undefined in the grand scheme of things -- it can be a single statement,
an entire program, or anything in between. As such, it is completely
useless in any sort of deterministic sense.

Since everything is a "sentence", a "sentence" is meaningless to
consider, except in the context of the "NEXT SENTENCE" statement.

The sentence is just a throwback to that cute, but totallly wrong, idea
that people who speak english are able to write programs.
Warren Simmons

2004-05-15, 10:30 pm

Joe Zitzelberger wrote:

> In article <Of9pc.81081$FH5.1858642@news20.bellglobal.com>,
> Donald Tees <donald_tees@sympatico.ca> wrote:
>
>
>
>
> I really have to disagree with you here. The sentence is completely
> undefined in the grand scheme of things -- it can be a single statement,
> an entire program, or anything in between. As such, it is completely
> useless in any sort of deterministic sense.
>
> Since everything is a "sentence", a "sentence" is meaningless to
> consider, except in the context of the "NEXT SENTENCE" statement.
>
> The sentence is just a throwback to that cute, but totallly wrong, idea
> that people who speak english are able to write programs.

Some people believe that was the purpose of English Source. DON'T
BELIEVE IT. The real reason at the start of this movement was that lots
of programs were written in lots of languages even in binary.
Regardless of the good intentions of some, documentation was not
always enough to maintain the program or to evaluate
the methods used to solve problems. Enough people wanted
to address that problem and establish a single coding
method for several good reasons.

The approach was tested for one computer,then using
the same language, on another computer at taxpayer
cost. The forward thinking people of the time decided
that USERS needed to get behind this as Vendors did not
have the motivation. From this CODASYL WAS CREATED,
AND SEVERAL MANUFACTURES AND USERS COMBINED TO WRITE
THE SPECS, AND set up a method for maintenance. Even
though some participation claims the effort was all
vendor, most of it was shared with users, and their
willingness to buy what they wanted, not what the
vendor wanted to sell.

I was there, and I know.

Warren Simmons
Howard Brazee

2004-05-17, 1:30 pm

For me another reason for a period is that it guarantees a full stop even after
code is inserted by my pre-compiler.

If the pre-compiler sticks in code containing error checking IF statements, I
want to make absolutely sure everything (seen and unseen) is fully terminated.
A full stop period does this.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com