[Lazarus] Code Observer notes

Alexander Klenin klenin at gmail.com
Tue Apr 21 05:20:55 CEST 2009


Mattias Gaertner wrote:
> On Mon, 20 Apr 2009 12:14:18 +1100
> Alexander Klenin <klenin at gmail.com> wrote:
>
>   
>> (4g) again seems simple, but 'auto-fixing' can in this can
>> make things _worse_ by hiding the problem. Consider the code (idented
>> by '~' characters): 
>> for i := 0 to High(A) do
>> ~~if A[i] > m then
>> Writeln(A[i]);
>>
>> The actual error is a missing 'm := i' line after the if, but
>> formatter would change it to
>> for i := 0 to High(A) do
>> ~~if A[i] > m then
>> ~~~~Writeln(A[i]);
>>
>> Obtaining correctly formatted but semantically wrong code.
>> Hint, on the other hand, will simply point programmer to the
>> problematic location where he will hopefully notice and fix it.
>>     
>
> Ok, the above example is a good. I thought you meant showing wrong
> indentation in general. That would not make much sense, because the
> indentation rules belongs to the code formatter and makes only sense
> for units you wrote.
> So the code explorer can scan for lines 'do' and 'then' lines where the
> following line is indented less or equal. Of course some programmers
> will switch off the "equal".
>
>   
while a nice idea, even this is not "that" easy

~~if a = 1 then
~~begin // if it should be on it's own line
end;

1) the begin is *or* is not expected to be intended, so the rule above 
should carter for that?
2) the end should be aligned with the start of the line, that did have 
the begin

~~if (a = 1) and // some very long condition or comment
~~~~~(b=2) then
~~~~writeln;

Imho is correctly indented, because the then is already moved in.
(in fact the 2nd condition line(5) is intended more (aligns the "(" ) 
than the "writeln" line(4))


if a = 1 then b:=2;
writeln(b);

if a = 1
then b:=2;
writeln(b);

the line continues behind the "then" => no indent is expected.

if a = 1 then b:=2 else
writeln(b);

=> I had no idea what indent was expected here?



More information about the Lazarus mailing list