[fpc-devel] Local variable names and colision with attributes/properties names
md at delfire.net
Thu Sep 27 16:48:50 CEST 2012
On Thu, Sep 27, 2012 at 11:30 AM, <michael.vancanneyt at wisa.be> wrote:
> On Thu, 27 Sep 2012, Marcos Douglas wrote:
>> On Thu, Sep 27, 2012 at 11:01 AM, Jonas Maebe <jonas.maebe at elis.ugent.be>
>>> On 27 Sep 2012, at 15:51, Marcos Douglas wrote:
>>> What is the advantages to the compiler return the error bellow?
>>> ERROR: unit1.pas(31,3) Error: Duplicate identifier "FooVar"
>>> Why the compiler do not respect the scope, ie, the local variable
>>> should have the preference, I'm not right?
>>> Yes, but the human brain is very good at confusing such things, and it's
>>> very easy to accidentally assign something to a local variable instead of
>>> a field.
>> Only Pascal uses that way?
> No, the brain works that way.
> The FPC team decided to protect you from accidental mistakes by forbidding
> this special case in $mode objfpc.
> For me, it has become second nature never ever to have a variable with the
> same name as a property, even in Delphi.
How do you know if you are using a function or method?
For example, I can code a StrToInt method in my class. You can extend
it. The "StrToInt method" is now in other unit and you "can't see it".
Now you code:
i := StrToInt(x);
Which StrToInt are you using? How our brains could help here?
BUT, if you use:
... you know what is happening.
But this is a programmer's choice, ie, using or not the Self. The
problem, IMHO, is that I can't choose when we talk about local
More information about the fpc-devel