[PPL-devel] Redundant elses

Matthew Mundell mattm at comp.leeds.ac.uk
Tue Oct 4 15:31:43 CEST 2005


Roberto Bagnara <bagnara at cs.unipr.it> writes:

> Matthew Mundell wrote:
>> Log message:
>> 	Take out two redundant `else' and a redundant `if'.
>
> What do you mean by redundant else?

The `else' repeats the information implied by the final return or
goto.

> Notice that source code is more than its semantics: the fact
> that with and without the else the behavior is the same is not
> a good reason to prefer the version without (or the version with
> the `else').

Adding the else makes it less clear that the body of the "then" branch
of the `if' always ends in a return or goto.

> If, in addition, you have something of the form
>
>     if (a)
>       ...
>     else
>       // comment
>       return ...

Did you mean this?

     if (a)
       return ...
     else
       // comment
       ...

>
> then taking out the else without revising the comment can
> do more harm than good.

The comment still applies to the code that was in the else branch.

>
> More generally, the rationale for such changes is as follows:
>
> - either things are left as they are on the grounds that who
>    wrote the code knew better if the `else' there was making
>    things more readable or not;
> - or the issue is raised globally, discussed at length,
>    documented in the STANDARDS file and then systematically
>    applied to whatever code.

OK, I will resist from changing such code.



More information about the PPL-devel mailing list