[Lazarus] clarification / Re: constant-highlight ? [Re: quick opinion poll / pascal highlighting "case"]

Jürgen Hestermann juergen.hestermann at gmx.de
Wed May 26 17:54:49 CEST 2010


Duncan Parsons schrieb:
> if you indent as waldo suggests certain bugs or compilation issues can be more immediately apparent - 
> do the begins & end match up? It's difficult to see when they are at the same level as the rest of the code.

If indentation is "overworked" it doesn't tell you very much anymore. If nearly each line is indented, then it becomes unclear and confusing to me. For very short code snippets it may work but if you have 10 or 20 levels of indentation (nested WITH, CASE, FOR, IF, ...) then adding an artificial indentation for each BEGIN/END pair would nearly double the number of indentations and would make it very complex IMO. Also, the indentation should be independend on whether only one command follows or multiple:

if a=b then
   do-something

and 

if a=b then
   begin
   do-something
   do-something-else
   end;

should be indented identically to stay logical. Having it

if a=b then
   begin
      do-something
      do-something-else
   end;

would also clutter it too much IMO. The chance of consecutive lines starting in the same column is much less. And only they give a certain structure in the code. Also, whenever I have an indentation I know that this means that the linear code flow is interrupted by a loop or a branch.

Regarding missing BEGIN/ENDs: They may not stay out so much if they are aligned with the block but you can still check easily whether each block (of more than one command) starts with a BEGIN and ends with an END. Also, this is needed much less often than checking the code flow.

> Some places I've been like the begins to be inline with a conditional/loop declaration/etc, but I've never liked that. With one (large multinational) Their chosen style for if/elseif/else was:
> if x then begin
>   code
> end else if y then begin
>   code
> end else begin
>   code
> end;
> Which I found to be as helpful as a ice teapot, as scanning down you see one if with three ends and no context for what was happening in between..

Yes, I would also not do it that way. Just imagine a missing BEGIN or END. Or adding another command in front of the second IF statement: You would have to enclose the new statement and the following IF with BEGIN/END. But where to place them? You can't see it immediately. But when having it formatted like this

if x then 
   begin
   code
   end 
else 
   if y then 
      begin
      code
      end 
   else 
      begin
      code
      end;

you can immediately see that the new-command has to be inserted like that:

if x then 
   begin
   code
   end 
else 
   begin
   new-command
   if y then 
      begin
      code
      end 
   else 
      begin
      code
      end;
   end;






More information about the Lazarus mailing list