[fpc-devel] Local variable names and colision with attributes/properties names

Michael Van Canneyt michael at freepascal.org
Thu Sep 27 19:43:14 CEST 2012



On Thu, 27 Sep 2012, Marcos Douglas wrote:

>>
>> I hope not :-)
>
> Of course the second is (a little) better.
>
> But, If you permits:
> for i := StardValue to EndValue do
>  MyArray[i] := i;
>
> Now is more readable. More verbose than the first but less verbose
> than second.  ;)
>
>> And it's not about the size of variable names. It's just about avoiding
>> duplicate names which can lead to confusion.
>
> You right but:
> - prefix increases the size   :P
> - variables abbreviated are more easy to programmers do not use the
> same names to, objects, primitives variables, etc.

Once we had the following code in Delphi:

Procedure TMyComponent.DoSomething;

Var
   B : String;
begin
   // complex code to calculate B. Prop is a property of the component.
   Prop:=B
end;

Someone, while fixing a bug, introduced then

Procedure TMyComponent.DoSomething;

Var
   B : String;
   Prop : String;

begin
   // complex code
   Prop:=B
end;

And all of a sudden, our program no longer worked. 
It took us a long time to find the error, namely an newly introduced local variable.

This kind of error is simply impossible in objfpc mode.

Michael.



More information about the fpc-devel mailing list