|
On Wed, 9 Oct 1996, Don Stanley <don_stanley@IBM.NET> wrote:
>Its a well accepted and clearly defined and taught axiom of computer
>programming in virtually any language that IF an ELSE is available THEN
>you use it. I find that the syntax without an else is confusing, and its
>impact on efficiency can be enormous ....
>I've always been of the opinion that omitting the else is similar to
>using goto's. There are ALMOST always good reasons for not doing it.
There have been a few replies to my original post concurring with Don's
point above. I simply don't agree that the syntax is confusing where
ELSE isn't used - to me, because nesting is only *necessary* in certain
cases where the conditions *aren't* mutually-exclusive, the use of
nesting when the conditions *are* mutually-exclusive is misleading! (I
think to myself 'doesn't the programmer realise those conditions are
mutually-exclusive?'). For example, in:
if x=1 then do;
<action 1>
end; else if x=2 then do;
<action 2>
end;
one would summarise the conditions necessary for Action 2 happening as
'action 2 only happens when (x is not 1) and (x is 2)'. The redundancy
in this summary is what I think makes this construct logically inferior
to sequential IFs.
However, I have already agreed that this is largely a question of
personal taste, and of course I agreed in the original post that there
are efficiency gains to be had in the wise use of nested IFs.
I think the uses of nesting and goto are quite different cases - the
impact on a program of using/not using nesting is largely limited to
efficiency, whereas using goto directly and drastically affects the
program flow, undermining any attempt to build structure into a program,
and is therefore much more dangerous.
|