Re: Where are spaces required in COBOL source code?
- From: "Chuck Stevens" <charles.stevens@xxxxxxxxxx>
- Date: Fri, 27 May 2005 11:59:05 -0700
Let's try that again. Things got messed up in the editing, and perhaps I
was too abrupt.
<epc8@xxxxxxxx> wrote in message
news:1117154259.996313.163080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> The compiler ... requires a
> variable name to be separated by at least one space from the
> parentheses enclosing a subscript (or an expression denoting reference
> modification). ...
> 1. Was this ever part of a COBOL standard?
The basic concept stems from the historical fact that the rules for COBOL
are such that it is intended to be legible as English imperative sentences.
Spaces, in written English, are commonly used to separate words and
punctuation.
In the rules of the COBOL language, the concept of "separator" as a
syntactic element seems to have been
introduced in the '74 standard, and in that standard, a space is allowed but
not required before a left parenthesis. Before the introduction of the term
"separator", it's a bit tough to tell for sure.
I see some indication that a space was required by COBOL-60 and by the '68
standard between the data-name and the leading left paren. I also see some
evidence that the '68 standard prohibited a space between the leading left
paren and the first subscript, and between the last subscript and the
trailing paren.
The basic rules for '85 COBOL dictating where spaces are required are:
after separator periods, commas and semicolons; before an opening quotation
mark that isn't immediately preceded by a left paren; after a closing
quotation mark that isn't immediately followed by a close paren; and before
an opening pseudo-text delimiter; and between COBOL words and nonseparators
or any combination thereof.
> 2. I sometimes find it puzzling that spaces seem to be required around
> certain things in COBOL when I don't expect them to be.
COBOL wasn't designed to be about expressing formulae, it was intended to
allow the programmer to write in a language that a non-programmer stood a
chance of being able to read and comprehend, and critique as a
representation of business practices.
> For example
> after commas (in CALL),
Commas aren't required between arguments in a CALL in the first place, but
*separators* are. A "separator comma" may appear anywhere a "separator
space" may appear, but a "separator comma" consists of a comma *followed by
a space*. If you put a comma there, expect to put a space after it. But so
long as you have at least one space between the arguments, the compiler
should accept it.
> around the colon in reference modification (at
> least in the compilers I've tested)
I don't see any standard requirement that a ("separator") colon be either
preceded or followed by a space in reference modification, and our
implementation certainly doesn't require it. Have you checked your vendor's
documentation? Maybe a trouble report to the vendor is in order?
> and around operators in a COMPUTE
> expression.
English words are separated from each other by spaces, and spaces generally
figure into English punctuation. This is reflected in the fact that
arithmetic operators (+, -, *, /, **) aren't listed among the "separators"
in COBOL rules. In COBOL, syntactic elements of the language are separated
by "separators", which include spaces.
Note that in COBOL
COMPUTE A = B - C.
means something entirely different from
COMPUTE A = B-C.
which is one reason your COBOL compiler is likely to complain when you fail
to separate your syntactic elements with separators! Since you *have* to
separate the parts of "B-C" in this case to make sure the compiler
understands that it's two operators and an operand, it's considered a Good
Idea to separate the components of "B+C", "B/C", "B*C" and "B**C" as well,
even if your compiler allows you to "compact" them.
Getting as much as possible accomplished on a single line of source code
used to be considered the hallmark of Expert Coding. This has passed out of
favor -- even in languages where it is common like FORTRAN and ALGOL --
because it's rarely very readable and often difficult to maintain.
> Please note that the first language I learned was FORTRAN using
> fixed-form (punched card) format. There spaces are only meaningful
> inside string literals.
Getting as much as possible accomplished on a single line of source code
used to be considered the hallmark of Expert Coding. This has passed out of
favor -- even in languages where it is common like FORTRAN and ALGOL --
because it's rarely very readable and often difficult to maintain. It's
not just FORTRAN.
Fixed-form format is no excuse; standard COBOL was fixed-form format until
the introduction of the 2002 standard!
As far as punctuation goes, the rules for the Common Business Oriented
Language are not the rules for the Formula Translator. The idea that
Fortran's set of rules ought to suit the needs of a language built for an
entirely different purpose is not likely to be anything other than an
unfulfilled expectation.
> Is there a general rule about this for COBOL and has it changed with
> different versions of the standard?
The general stylistic rule for COBOL is that COBOL is based on English, in
which letters are combined into words that are separated by spaces and
punctuation marks. The punctuation rules are similar to those for English
as well, including the frequent requirement that certain punctuation marks
be followed by at least one space. Some specifics may have changed over
time, but a separator space where it is allowed is
rarely a Bad Idea in COBOL.
What is considered readable code in COBOL generally bears a very close
relationship to the rules of English punctuation. In that language,
typically, at least one space follows a comma or period or semicolon, a
parenthetical expression is separated from its preceding text by a space,
and the contents of a parenthetical expression most often are adjacent to
their enclosing parentheses. Such is the convention with COBOL.
-Chuck Stevens
.
- Follow-Ups:
- References:
- Prev by Date: Re: Where are spaces required in COBOL source code?
- Next by Date: Re: Where are spaces required in COBOL source code?
- Previous by thread: Re: Where are spaces required in COBOL source code?
- Next by thread: Re: Where are spaces required in COBOL source code?
- Index(es):
Relevant Pages
|