Re: Cobol work?
- From: "Rick Smith" <ricksmith@xxxxxxx>
- Date: Mon, 31 Oct 2005 03:33:53 -0500
"Joe Zitzelberger" <joe_zitzelberger@xxxxxxxxxx> wrote in message
news:joe_zitzelberger-58F137.22362830102005@xxxxxxxxxxxxxxxxxxxxxxxxxxx
[snip]
> Cobol, alone among languages, inverts equality tests in truly weird
> ways. Consider the common Cobol-only idiom:
>
> If a is equal to b
> continue
> else
> --do a not equal to b logic--
> end-if
>
> This is a code style that only a Cobol programmer could love...and it
> easily qualifies for the "obfuscated" label compared to the simple,
> clear, idiom used in every other programming language known to human
> kind.
It is most definitely not a "Cobol-only idiom": It is sometimes
found in C programs. (Especially those I have written!)
Since I am, admittedly, biased. Here is what Steve McConnell,
"Code Complete," 1993, pp 312-314, has to say.
Follow these guidelines when writing _if_ statements.
Write the nominal path through the code first; then
write the exceptions. Write your code so that the
normal path through the code is clear. Make sure
that the exceptions do not obscure the normal path
of execution. This is important for both readability
and performance. ...
Put the normal case after the _if_ rather than after the
_else_. Put the case you normally expect to process
first. This is in line with the general principle of putting
code that results from a decision as close as possible
to the decision.
Clearly, if the "nominal path" or "normal case" is to do
nothing, then either CONTINUE or a null statement should
follow the _if_ and the exception should follow the _else_.
McConnell then continues.
Follow the _if_ with a meaningful statement. Sometimes
you see code like the next example, in which the _if_
clause is null.
C Example of a Null _if_ Clause
if ( SomeTest )
;
else
{
/* do something */
...
}
Most experienced programmers would avoid code like
this if only to avoid the work of coding the extra null line
and the _else_ line. It looks silly and is easily improved
by negating the predicate in the _if_ statement, moving
the code from the _else_ clause to the _if_ clause, and
eliminating the _else_ clause.
H'm, "[m]ost experienced programmers would avoid" implies
'some experienced programmers would not avoid' (ignoring
the inexperienced who may not recognize what "looks silly").
These "some" then are the exceptions, or might I suggest
exceptional programmers, for whom clarity is more important
than avoiding "the work of coding" or what "looks silly". <g>
Code written "so that the normal path through the code is
clear" and "that the exceptions do not obscure the normal
path of execution" hardly "qualifies for the 'obfuscated' label".
.
- References:
- Cobol work?
- From: Martik
- Re: Cobol work?
- From: Judson McClendon
- Re: Cobol work?
- From: Christopher Pomasl
- Re: Cobol work?
- From: HeyBub
- Re: Cobol work?
- From: Michael Wojcik
- Re: Cobol work?
- From: Ian Dalziel
- Re: Cobol work?
- From: John Culleton
- Re: Cobol work?
- From: Oliver Wong
- Re: Cobol work?
- From: john
- Re: Cobol work?
- From: Michael Wojcik
- Re: Cobol work?
- From: Judson McClendon
- Re: Cobol work?
- From: Joe Zitzelberger
- Re: Cobol work?
- From: Judson McClendon
- Re: Cobol work?
- From: Joe Zitzelberger
- Cobol work?
- Prev by Date: Re: Cobol work?
- Next by Date: Re: Fibonacci program
- Previous by thread: Re: Cobol work?
- Next by thread: Re: Cobol work?
- Index(es):
Relevant Pages
|
Loading