473,395 Members | 2,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Your word on notation?

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
4 1420
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
"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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fazer | last post by:
Here comes another small question from me :-) I am curious as to how I should approach this issue. I would just want to parse simple text and maybe perhaps tables in the future. Would I have to...
3
by: Robert Mark Bram | last post by:
Howdy All! Is there any difference between referencing objects and attributes with dot notation or bracket notation? Example, document.formname.controlname document Can I access...
2
by: David | last post by:
After getting some help working through my bugs, I have what seems to be a robust, working word counter script. I post it here to benefit others that might want this in the future and so that if I...
7
by: Philipp Lenssen | last post by:
I would like to know what others do to prevent line-breaks, using &nbsp; For example, the guidelines for the company have certain words (like "Model XY", where "Model" and "XY" shouldn't be...
2
by: funcSter | last post by:
I was asked to program using the Dutch Notation with C#. I am not familiar with the Dutch notation at all. I use the Hungarian. I asked a programmer friend "What is the Dutch Notation?" He...
7
by: onetitfemme | last post by:
Hi, for some reason Firefox is apparently inserting a new line somehow after some IPA symbols which I have written in their hexadecimal notation. Also, I would like to have two spaces by...
4
by: Gregory Edigaroff | last post by:
Hello, Everybody! Ok, I urgently need the solution for a following task in C++. This is the task from programmers contest, so I believe somebody have a solution for it. I need either a full...
22
by: bearophileHUGS | last post by:
>From this interesting blog entry by Lawrence Oluyede: http://www.oluyede.org/blog/2006/07/05/europython-day-2/ and the Py3.0 PEPs, I think the people working on Py3.0 are doing a good job, I am...
3
by: gcmartijn | last post by:
Why is this not working ? bla = 'hondenriem' print bla # correct ! (= hond) print bla # nothing ! (= en) print bla # nothing ! (= riem) Why don't bla and bla won't work ? I use this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.