Eike Lange wrote:
On Wed, Nov 06, 2002 at 01:57:34AM +0100, Frank Heckenbach wrote:
Eike Lange wrote: As has shown already in this thread, not all programms consider an empty `else' part a bug. Actually, there's one situation where I can imagine it to be useful, the dangling `else' problem: if foo then if bar then baz else else qux Though alternatively, one can use `begin'/`end' to avoid the empty `else' part: if foo then begin if bar then baz end else qux
The latter looks quite more natural to me (and is the way, the GPCS prefers).
Not strictly. It does mention the example with `begin'/`end', but more as an example for using `begin'/`end' around a single statement, not in contrast to the empty `else' case (which it doesn't mention at all).
IMO using a comment instead of an empty `else' statement makes the first example more readable:
if foo then if bar then baz else { empty } else qux
IMHO, both ways are a little dangerous (one might be tempted to remove the "superfluous" `begin'/`end' when not looking carefully), so both ways might deserve a comment -- in the empty `else' case, as you showed, in the `begin'/`end' case I'm not sure where to best place the comment ...
Of course, whenever easily possible, one should avoid the situation as Chuck said, but sometimes it's not easily possible (see Dave's example if I'm not missing anything).
Warnings and empty `else' might be a topic for "GNU Pascal Coding Standard (* Assorted Tips )" if you agree.
I agree. Could you write the text for the English and German versions?
Frank