Re: Private variables question



Phill Harvey-Smith wrote:

Hi,

This is more from a mater of interest than any technical reason, but
there seems to be a lot of code around where the private variables
are called FSomething e.g.

TYPE TSomeType=class(object)
PRIVATE
FLocalVar : INTEGER;
PUBLIC
PROPERTY LocalVar : INTEGER READ FLocalVar;
END;

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 ?


Some developers (like me) prefix private variables or _fields_ in a
class to make them easier to spot. I picked it up a long time ago
because it seemed to be a fairly common convention that made sense.

Kind of like prefixing classes with T, interfaces with I or arguments
with A (less common?).

I've also gotten into the habit of prefixing local variables with L.
This isn't so much to make them easier to spot (which it does), but to
make it less likely that a logically named local variable name won't
inadvertently hide another identifier with a higher scope and avoiding
difficult to find bugs.

Use whatever you feel comfortable with as long as you're consistent.

--
Regards,
Bruce McGee
Glooscap Software
.



Relevant Pages

  • Re: underscore prefix
    ... This is olb naming convention for private variables. ... convention you should use m_ as prefix for private members ... > explanation for the reason for this. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Private variables question
    ... This is more from a mater of interest than any technical reason, but there seems to be a lot of code around where the private variables are called FSomething e.g. ... Me on the other hand I couldn't care less what the prefix is I just use the auto complete feature of the IDE which auto prefix the private members with F and it doesn't give me an option which I can change it. ...
    (borland.public.delphi.non-technical)
  • Re: underscore prefix
    ... > I think the guidlines actually discourage use of m_ when it says "Do ... >>This is olb naming convention for private variables. ... >>convention you should use m_ as prefix for private members ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: underscore prefix
    ... not apply a prefix to field names or static field names." ... >This is olb naming convention for private variables. ... >convention you should use m_ as prefix for private members ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: To Hungarian or not to Hungarian
    ... prefix that denotes whether the item is a parameter, ... The type, but not the scope. ... I personally do not use prefixes for local variables. ... "Death is one of the few things that can be done as easily lying ...
    (borland.public.delphi.non-technical)