Darima Lamazhapova writes:
> I'm novice in FORTRAN, and also I don't know is my question is suitable
> here. My question concerns good programming style. I was taught that
> GOTO operator is an obsolescence and should not be used. But in many
> fortran programs I meet GOTO very often (e.g. to organize the cycle
> using IF construction). Does the good style of FORTRAN programs allow
> using operator GOTO?
Certainly a suitable topic, though one that tends to get revisited a
bit too often without really much new coming up. In (relatively)
short (for me) summary because I need to get back to some other work:
Questions of style are difficult to answer definitively. Personal
styles do vary and are a subjective matter. There are some general
principles that are fairly widely accepted, but there probably isn't a
single point that you won't find someone disagreeing with. So terms
like "good", "bad", "right", "wrong" and the like typically need to be
qualified with phrases like "in my opinion" when applied to questions
of style. With that qualification....
Good code organization cannot be achieved by cookbook formulae such
as using a given set of statements. Conversely, using some statements
(such as GOTO) does not automatically make code organization poor.
I'm afraid its harder than that. It is unfortunately all to common
to read things like that "GOTO's are bad programming practice"
because its a lot simpler to make such statements than to really
understand the basis for them.
So, yes, a well-written Fortran program can use GOTO and still be
considered to have good style. I use GOTO's in my programs, and I
consider myself to have a reasonable style. (Obviously a biased
opinion, which plenty of people might disagree with).
*BUT* *BUT* *BUT*
Although the statement that "GOTO is bad style" is an over-simplified
generalization, one should understand *WHY* people make this
statement. Excessive use of GOTO statements is very probably a
symptom of poor code organization. The basic problem is the poor
organization - not just the GOTOs. Getting rid of the GOTOs won't
automatically fix the poor organization; it may well make it worse.
The excessive GOTOs are more a symptom than a cause. But if you use
GOTO "very often" I suspect I'd find the style...um...let me avoid
saying "poor"...how about "not to my taste."
Assuming that you are using a modern version of Fortran (f90/f95),
look into the new form of the DO loop and the CYCLE and EXIT
statements as tools to help your organization. But they are just
tools. Again, using them won't automatically mae your organization
"good".
I've written enough for now, so I'll not try to describe what really
makes "good organization". Its hard for me to describe anyway.
Probably others here can articulate it better than I can.
--
Richard Maine
[log in to unmask]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|