Simon Wright <[email protected]> writes:

> Something like this code was recently posted on StackOverflow, and indents as 
> shown. 5.1.7 (from monotone, just now).
>
> procedure Nested_If_Else is
> begin
>    if 1 > 2 then
>       null;
>    else if 2 > 3 then
>       null;
>    else if 3 > 4 then
>       null;
>    else
>       null;
>    end if;
>    end if;
>    end if;
> end Nested_If_Else;

I'm guessing this was written by a C programmer, who did not learn about
'elsif'.

This is strictly equivalent to:
   if 1 > 2 then
      null;
   elsif 2 > 3 then
      null;
   elsif 3 > 4 then
      null;
   else
      null;
   end if;

So that's one right solution.

> I see that if I put a newline after the ‘else’s then all is OK;

Giving:

   if 1 > 2 then
      null;
   else 
      if 2 > 3 then
         null;
      else
         if 3 > 4 then
            null;
         else
            null;
         end if;
      end if;
   end if;

This is the other right solution; it makes things clearer if you start
adding code between the 'else' and 'if', or between the 'end if's.

> perhaps it’s right for ada-mode to penalize such horrid style!

Yes, it's a good clue that you should be using one of the two solutions
above.

I'll leave it alone; I looked at the code that produces this,
and changing it would change a lot of other stuff.

I will add this as a test case, with a comment about bad style.

-- 
-- Stephe

_______________________________________________
Emacs-ada-mode mailing list
[email protected]
http://host114.hostmonster.com/mailman/listinfo/emacs-ada-mode_stephe-leake.org

Reply via email to