Martin schrieb:
On 26/05/2010 06:06, Jürgen Hestermann wrote:
But why have an indentation after BEGIN? There is no new block to
start after BEGIN. I would indent like this:
begin
if foo then
begin
bar := foo;
Who is to say that the begin is part of the block? (Anyone is free to
tread it as such, but where is it officially defined?)
For me it's not a matter of definition but of logic. A "block" is a sequence of
commands that are executed step by step one after the other. I always align these
commands on the same column. A conditional branch or a loop breaks this linear execution
so another level of indentation is added. And because a single command is the same kind
of block as multiple commands (enclosed with BEGIN/END) it's logical to align them all at
the same column. I then see immidiately when a block (of more than 1 command) does not
start with a BEGIN or does not end with an END. Having this logic is very important to me
so that I can see the order of execution. When having a branch like this
if xxx then
begin
...........
end
else
begin
...........
end;
and the number of commands between BEGIN/END is large then I only have to
scroll down (with the cursor at the BEGIN) to find the matching END. Same with
a loop:
for xxx do
begin
.........
end;
Everything between BEGIN and END is part of the block which is executed by the
FOR loop. And the same for REPEAT:
repeat
.....
.....
until
It's the same logic, although no BEGIN/END pair is needed. If I would indent
one level more with each BEGIN/END then the indentation would be different with
or without these indentifiers. When the block consists of only one command or
when I have a REPEAT loop then the indentation would be less. To me that's
illogical and inconsistend and harder to read.
But, it seems that everybody has got used to his own style so it's unlikely
that someone would change their style.
--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus