Re: To Hungarian or not to Hungarian
- From: "Doug Chamberlin" <dougchamberlin at earthlink dot net>
- Date: 1 Nov 2007 09:00:59 -0700
Kevin Frevert wrote:
Is Hungarian notation really dead? What standards do you use?
Yes, it is generally frowned upon these days and has been for a while.
The name should reflect the function or purpose of the item. Also, in
the teams I've lead and participated for quite a long time, the scope
of a variable is seen as the most important "addition" that might be
tacked onto the name. Therefore, we use a single letter prefix that
denotes whether the item is a parameter, a local variable, a global
variable, or a constant. For example,
function GetIDFromName(const pName: string;pIDCandidate: Integer):
Integer;
var
vID: Integer;
vName: string;
begin
vName := UpperCase(pName);
if vName='ABC' then
vID := pIDCandidate
else if vName='DEF' then
vID := gID
else
raise Exception.CreateFmt('GetIDFromName: Unable to obtain ID for
%s,[pName]);
Result := vID;
end;
Admittedly, a somewhat silly example, but I hope you get the idea. This
naming style allows you to create a local vName with the same base name
as the param without having to invent something strange. The similarity
of names stringly suggests the vName value is a local working copy of
the pName value. (BTW, using both allows you to preserve the original
value of pName in case you need it, such as when handling the
exception.)
.
- Follow-Ups:
- Re: To Hungarian or not to Hungarian
- From: Kevin Frevert
- Re: To Hungarian or not to Hungarian
- References:
- To Hungarian or not to Hungarian
- From: Kevin Frevert
- To Hungarian or not to Hungarian
- Prev by Date: Re: Delphi in Florida?
- Next by Date: Re: To Hungarian or not to Hungarian
- Previous by thread: To Hungarian or not to Hungarian
- Next by thread: Re: To Hungarian or not to Hungarian
- Index(es):
Relevant Pages
|