By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

Your word on notation?

P: n/a
I have been told not to use preceding underscores when notating data
members for example. What kind of notation do you use in general? I have
seen Microsoft uses hungarian notation a lot. Is that the most common one?
I also recognized that the more abstract a language becomes, the less
people care about proper notation (i.e. I haven't seen any C# or Java
code using anything even close to hungarian notation).
I have even recognized this behavior for myself. The less C-like C++
code I write, the less I care about notating it. For example, I found
that notating pointers with a preceding p helped a LOT not to confuse it
with anything else but being just a pointer.
In my more recent code I have to look really hard to find any pointers
at all, so I don't care about it anymore. Same for strings.

Do you use any specific notation at all?

--
Regards,
Matthias
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Matthias wrote:
I have been told not to use preceding underscores when notating data
members for example. [...]
Leading underscores can mean you're using a reserved identifier and
I, for example, try not to tempt my compiler.
Do you use any specific notation at all?


Some old habits die hard and I still use 'p' prefix for pointers and
'n' for counters. When I get to write from scratch I try not to use
leading underscores. They just make everything less readable for me.
At this point in my career I maintain a lot of somebody else's code,
so I try to use their notation to keep the code consistent unless it
is inconsistent to begin with in which case I try to make the least
amount of changes to bring it to a consistent state.

Don't get hung up on style unless your boss tells you to. Pick one
and follow it. Consistency is more important than any particular way
of naming your objects.

V
Jul 23 '05 #2

P: n/a
"Matthias" <no****@digitalraid.com> wrote in message
news:cu*************@news.t-online.com...
I have been told not to use preceding underscores when notating data
members for example.
IMO that's good advice. In many contexts (but not the
one you cite), names beginning with an underscore are
reserved to the implementation. Rather than try to remember
these rules, I also advise avoiding use of leading underscores
altogether. Or perhaps whoever told you the above was simply
dictating 'shop rules'.
What kind of notation do you use in general?
I try to use names which strike a balance between
descriptiveness and conciseness.
I have
seen Microsoft uses hungarian notation a lot.
Yes, their code is full of it. :-)
Is that the most common one?
Not for all C++ code in general, I doubt it.
I also recognized that the more abstract a language becomes, the less
people care about proper notation
The only 'proper' part of notation C++ cares about is correct
syntax. Subject to a few rules about reserved names, it
doesn't care what you name your identifiers. But again,
I recommend being descriptive. One reason I dislike
HN is that it unnecessarily binds a name to a type.
E.g. if I create an object of one type (e.g. 'int') and
give it some prefix to indicate 'int', and later I need
to change the type (to e.g. 'long'), I must remember
to change the prefix (and grep all the code where it's
referenced). A maintenance nightmare.

(i.e. I haven't seen any C# or Java
code using anything even close to hungarian notation).
Notation (as you're describing it) has nothing to do
with which language you use, except that the languages
rules about e.g. reserved names, etc. must be observed.
I have even recognized this behavior for myself. The less C-like C++
code I write, the less I care about notating it.
IMO one should simply care about making the code readable
and maintainable (to and by others, not only the author).
For example, I found
that notating pointers with a preceding p helped a LOT not to confuse it
with anything else but being just a pointer.
That's one case where I'm ambivalent about such a prefix.
(Since 'p' indicating 'pointer' is more generic that indicating
a specific type). However, I don't use this prefix either
(but I'll often name a 'temporary' pointer object as simply
'p' in a simple routine).
In my more recent code I have to look really hard to find any pointers
at all,
A pointer is easily recognized by reading its declaration (because
of the asterisk).
so I don't care about it anymore.
I don't know if this is the case for you, but I see many
folks using pointers in C++ where they're not necessary,
where a better, simpler solution exists.
Same for strings.
What do you mean? I don't see any need to indicate in an
identifer that an object has a string type. I just name
it what it means, e.g.:

std::string customer_name; /* imo the identifer makes it obvious
that 'customer_name is a string */


Do you use any specific notation at all?


Yes. Descriptive.

-Mike
Jul 23 '05 #3

P: n/a
Mike Wahler wrote:
"Matthias" <no****@digitalraid.com> wrote in message
news:cu*************@news.t-online.com...
[...]
In my more recent code I have to look really hard to find any pointers
at all,

A pointer is easily recognized by reading its declaration (because
of the asterisk).


Notations exist not to aid reading declarations. They exist to aid
reading and understanding code while declarations are not in the view.
Often those declarations are in the header, especially when members
are concerned.
[...]

Jul 23 '05 #4

P: n/a

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:yq*******************@newsread1.mlpsca01.us.t o.verio.net...
Mike Wahler wrote:
"Matthias" <no****@digitalraid.com> wrote in message
news:cu*************@news.t-online.com...
[...]
In my more recent code I have to look really hard to find any pointers
at all,

A pointer is easily recognized by reading its declaration (because
of the asterisk).


Notations exist not to aid reading declarations. They exist to aid
reading and understanding code while declarations are not in the view.
Often those declarations are in the header, especially when members
are concerned.


Yes, you're right, I suppose I misunderstood the context
of the question.

But I still feel that pointers aren't really hard to spot
because context usually indicates that they're pointers.
Of course I'm saying this from a perspecitive of reading
a particular piece of code for meaning, not arbitrarily
scanning code, looking for 'where are the pointers'.

Finally, I'm sure you'll agree that there will never be
a consensus on what is the 'best' notation.

-Mike
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.