Subject: Re: policy -- taking the code guidelines seriously
Date: Wed Aug 22 2001 - 08:16:52 CDT
"Håkan Waara" <email@example.com> wrote:
> > and using "m" (for member) or "f" (for field) for
> and g for globals, p for pointers, h for handles. ;)
Warts like 'i' and 'f' in Hungarian notation and warts
like 'm' and 'g' serve diffent purposes. The former
indicate the type of the variable. This is more of an
issue in C than C++, with its stronger type checking,
but it doesn't go away completely. Unexpected behavior
can result if the wrong type is used in certain
expressions. Warts could alert you to the problem if
you know the possibility existed, but knowing it exists
is the harder and more important part. Also, it is a
maintenance problem keeping the name and type of an
The latter minimize name space pollution. The chance of
a collision of nontrivial names is low, but it doesn't
hurt to take extra precaution. I prefer adding a '_'
suffix to member variables, so that I can use the same
name minus the suffix as a member function to get its
value. For example, the getter function for the private
member variable prompt_ would be prompt().
Warts like 'h' and 'p' are a different type. They are
part of the name of the object, just like a dialog box
that applies formatting changes might be
called "formatDlg". That said, I don't always use them
inside member functions. For example, if a member
function returns a constant pointer to a member object
for use in another member function, I'd probably assign
it to "member" and not "pMember". Maybe this lack of
consistency is worst of all.
I think that the "sz" wart, for a NULL terminated
string, is defensible. Ideally, the complexity of
dealing with character strings would be encapsulated in
a class, but there will always be a need to pass or
receive the simpler representation to and from
functions. And the "sz" wart is an instantly
recognizable flag indicating what is expected.
While we're on the subject of naming conventions, I hate
the practice of shortening a variable name by just one
or two characters. For example, "prompt"
becomes "prmpt". The keystrokes saved usually aren't
worth the loss of clarity.
To unsubscribe from this list, send a message to
firstname.lastname@example.org with the word
unsubscribe in the message body.
This archive was generated by hypermail 2b25 : Wed Aug 22 2001 - 08:16:57 CDT