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 4 1445
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
"Matthias" <no****@digital raid.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
Mike Wahler wrote: "Matthias" <no****@digital raid.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.
[...]
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:yq******** ***********@new sread1.mlpsca01 .us.to.verio.ne t... Mike Wahler wrote: "Matthias" <no****@digital raid.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 save the word file and open it in a text editor? That
would kind of....suck... Has anyone else tackled this issue?
Thanks,
|
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 attributes and objects equally with both?
|
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 ever lose
my copy I can come back here to find it :) Some other scripts that I
used for inspiration failed when confronted with whitespace before the
string or miscalculated when encountering linefeeds and other
non-space spaces, so I made mine...
|
by: Philipp Lenssen |
last post by:
I would like to know what others do to prevent line-breaks, using
For example, the guidelines for the company have certain words (like
"Model XY", where "Model" and "XY" shouldn't be separated. Fair enough,
I use the non-breaking space for that.
How about things like:
- 10 to 100 KM/H
- 7 to 8 years
|
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 replied,
"Do you mean HUNGARIAN notation?"
So I thought maybe the person who told me to use the Dutch notation
must have been mistaken. Upon doing some research, I realise that the
DUtch notation does exist (hehe pardon my ignorance!), BUT I can't...
| |
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 default in textual fields
from tables.
What would be the style sheet statements to achieve this?
|
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 source code or a simple description of algorithm to solve this task.
thank a lot in advance.
Unit Conversion
A (measurement) unit is here represented by a single word containing only lower-case letters. All
|
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 not expert enough (so I don't post this on the Py3.0
mailing list), but I agree with most of the things they are agreeing
to. Few notes:
- input() vanishes and raw_input() becomes sys.stdin.readline(). I
think a child that is learning to program...
|
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 version:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |