Re: Private variables question
- From: "Joanna Carter [TeamB]" <joanna@xxxxxxxxxxxxx>
- Date: Wed, 30 Apr 2008 14:31:15 +0100
Phill Harvey-Smith a écrit :
What I guess i'm asking is why prefix it with 'F' ? I have been tending to use 'Pr' in my own code for Private, I guess the compiler does not care, just wondered why it seemed to be a convention ?
More than likely because private variables are known as "fields".
Although I have given up on using prefixes unless it is an underscore for private fields, and that only because Delphi is not case-sensitive.
In C#, I would use :
{
public class Person
{
private string name;
private int age;
public string Name
{
get { return name; }
set { name = value; }
}
public int Age
{
get { return age; }
set { age = value; }
}
}
}
.... so in Delphi I would use :
type
Person = class
private
_name: string;
_age: integer;
public
property Name: string
read _name
write _name;
property Age: int
read _age
write _age;
end;
AFAICR, the only other occasions that prefixes are really needed are for interfaces (IMyInterface) and enumerations because you can't qualify them to their type like you can in C# (MyEnum.One, MyEnum.Two, etc)
Of course, there are some that would sentence me to the "Comfy Chair" for such heresy as relying on case sensitivity in C# but, once you get used to it, not having to embellish names just to differentiate visibility kinda grows on you :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
.
- Follow-Ups:
- Re: Private variables question
- From: Bruce McGee
- Re: Private variables question
- References:
- Private variables question
- From: Phill Harvey-Smith
- Private variables question
- Prev by Date: Re: Private variables question
- Next by Date: Re: Private variables question
- Previous by thread: Re: Private variables question
- Next by thread: Re: Private variables question
- Index(es):
Relevant Pages
|