473,394 Members | 1,817 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,394 software developers and data experts.

Hungarian notation

I am looking at starting a new piece of work for a company who are
heavily into hungarian notation for C coding.

Any killer arguments for NOT carrying this terrible practice forward
into new C++ code?
Mar 21 '08 #1
18 4208
On Mar 21, 8:02*am, dom.k.bl...@googlemail.com wrote:
I am looking at starting a new piece of work for a company who are
heavily into hungarian notation for C coding.

Any killer arguments for NOT carrying this terrible practice forward
into new C++ code?
Variable names are like comments - they can lie. If the type of a
variable changes, you either have to hunt down every occurrence of it
to change, or allow it to fib about the type.
Mar 21 '08 #2
do*********@googlemail.com wrote:
I am looking at starting a new piece of work for a company who are
heavily into hungarian notation for C coding.

Any killer arguments for NOT carrying this terrible practice forward
into new C++ code?
It is anathema to generic programming. You might also consider asking a
Python group of the ways in which it would mess with duck typing.
Mar 21 '08 #3
On Mar 21, 4:31 pm, Andy Champ <no....@nospam.comwrote:
Andrew Koenig wrote:
<snip>
*The* Koenig?
And he ain't the only C++ celeb that lurks here...

http://tinylink.com/?xUpZmTcf1j
Mar 21 '08 #4
On 21 mar, 14:06, dave_mikes...@fastmail.fm wrote:
On Mar 21, 8:02 am, dom.k.bl...@googlemail.com wrote:
I am looking at starting a new piece of work for a company
who are heavily into hungarian notation for C coding.
Any killer arguments for NOT carrying this terrible practice
forward into new C++ code?
Variable names are like comments - they can lie. If the type
of a variable changes, you either have to hunt down every
occurrence of it to change, or allow it to fib about the type.
If the semantics of the variable changes, you'll want to do this
anyway.

The main argument against Hungarian notation as it generally
seems to be used is that it is pure obfuscation. In C or in
C++.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 22 '08 #5
On Mar 22, 11:06 am, James Kanze <james.ka...@gmail.comwrote:
On 21 mar, 14:06, dave_mikes...@fastmail.fm wrote:
On Mar 21, 8:02 am, dom.k.bl...@googlemail.com wrote:
I am looking at starting a new piece of work for a company
who are heavily into hungarian notation for C coding.
Any killer arguments for NOT carrying this terrible practice
forward into new C++ code?
Variable names are like comments - they can lie. If the type
of a variable changes, you either have to hunt down every
occurrence of it to change, or allow it to fib about the type.

If the semantics of the variable changes, you'll want to do this
anyway.
Semantics sure, but not type. If I use HN and my char * changes to a
CString or a std::string, I've got to change lpszFirstName to
strFirstName. Not the case if I just call it firstName.
Mar 22 '08 #6
On 22 mar, 04:23, Jeff Schwab <j...@schwabcenter.comwrote:
Andrey Tarasevich wrote:
Leading lowercase n has meant "unsigned integer" everywhere
I've ever seen it used.
The only place I've seen it use has been Fortran. Where a
leading i,j,k,l,m or n means signed integer.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 22 '08 #7
On 21 mar, 17:51, "Andrew Koenig" <a...@acm.orgwrote:
<dom.k.bl...@googlemail.comwrote in message
news:b2**********************************@i7g2000p rf.googlegroups.com...
I am looking at starting a new piece of work for a company
who are heavily into hungarian notation for C coding.
Then your best course of action is probably to follow the
golden rule: The people with the gold make the rules.
Take the view that they can't waste your time -- they can only
waste their money.
That's the engineer talking, not the scientist:-).

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 22 '08 #8
James Kanze wrote:
On 22 mar, 05:02, Andrey Tarasevich <andreytarasev...@hotmail.com>
>What "de-facto standard"? There's no "de-facto standard" of
using 'num' instead of 'n'.

There are several "standards": Merriam-Webster gives both
"count" and "number of", for example. From what I've seen, n
was well established in Fortran, and was used somewhat in the
early days of C (when external symbols were only distinctive in
the first eight characters), and num seems to have been wide
spread in Cobol. But there's absolutely no reason to not use
the real standard (i.e. Merriam-Webster, for US English) in
modern C++.
I'm generally with you on this one. I've recently been using
getNumElements for syntactic compatibility with a third-party library,
but I find it vaguely jarring for several reasons. I've even started
wrapping it in an overloaded size() method, so that:

size(some_container)

works regardless of whether the container is a std::vector or one of the
other library's container types.
But I don't think I'd take the standard as a good example with
regards to naming conventions. (Witness std::remove.)
It's certainly not perfect. I still try to follow the standard
library's lead wherever feasible, but I'd like to see a few changes in
the long run. For now, I'm busy digesting the upcoming syntactic
changes in the core language, and trying to get more familiar with the
newly added library features.

James, I know you've said before that the standard library does one
thing, but that code is different. How do you keep the code compatible?
If your type names begin with capital letters, how do you use an
algorithm that expects a C::iterator rather than a C::Iterator?
Mar 22 '08 #9
On 22 mar, 19:53, Jeff Schwab <j...@schwabcenter.comwrote:

[...]
But I don't think I'd take the standard as a good example with
regards to naming conventions. (Witness std::remove.)
It's certainly not perfect. I still try to follow the standard
library's lead wherever feasible, but I'd like to see a few changes in
the long run. For now, I'm busy digesting the upcoming syntactic
changes in the core language, and trying to get more familiar with the
newly added library features.
James, I know you've said before that the standard library
does one thing, but that code is different. How do you keep
the code compatible? If your type names begin with capital
letters, how do you use an algorithm that expects a
C::iterator rather than a C::Iterator?
Define both of them:-).

Seriously, templates do cause problems, and require some
thought. Before the standard library came along, for example,
all of my containers had a function iterator(), which returned a
GoF style iterator. I've seens worked out the necessary
techniques so that most of my iterators are both GoF type
iterators and ForwardIterators in the sense of the STL, but the
name of the function is a real problem---I can't effectively
change it without breaking a great deal of existing code, and
even if I could, what other name would be reasonable.

Luckily, for the most part, if you follow the philosophy of the
STL, anything involving templates and sequences uses iterators,
and not containers, so the name collision in the container
itself hasn't turned out to be a major problem.

More generally, of course, I do often have to ask myself which
is better. Should my XDR streams be called
ixdrstream/oxdrstream, or XDRInputStream/XDROutputStream. Given
that they're very closely modeled on iostream. And what about
my streambuf decorators (currently FilteringInputStreambuf and
FilteringOutputStreambuf).

(BTW: I use CamelCase because that's what all of my customers
have used. That's not really the issue here: you could pose the
question in terms of xdr_input_stream and xdr_output_stream just
as well.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Mar 23 '08 #10
In article <b2**********************************@i7g2000prf.g ooglegroups.com>,
<do*********@googlemail.comwrote:
>I am looking at starting a new piece of work for a company who are
heavily into hungarian notation for C coding.

Any killer arguments for NOT carrying this terrible practice forward
into new C++ code?
What about trying Argument by Ridicule:

http://www.drdobbs.com/cpp/184403804

Conversations: Hungarian wartHogs
Jim Hyslop and Herb Sutter

:-)

Mar 25 '08 #11
Yannick Tremblay wrote:
What about trying Argument by Ridicule:

http://www.drdobbs.com/cpp/184403804

Conversations: Hungarian wartHogs
Jim Hyslop and Herb Sutter
A rather prominent example of two well-recognized people engaging in
deliberate demagogy. It is interesting to note that they do seem to
understand the true meaning of the term "hungarian notation" since they
do touch it briefly at the beginning of the article (null-terminated
string example) and they also link the original article on "hungarian
notation".

However, once started, they quickly and quietly turn to deceiving the
reader by falsely presenting some ridiculous type encoding technique as
"hungarian notation". This demagogic technique is called "straw man
argument". An inexperienced reader will not notice the switch and indeed
might perceive the article as a valid argument against the notation,
while in fact it has nothing to do with it.

Note that they also use the same obviously false argument that the
change of variable type will trigger the need to change the variable
name in cases when "hungarian notation" is used - a dead giveaway that
they either have no idea what "hungarian notation" is (unlikely) or
(likely) deliberately pretend to have no idea.

Why are they doing this? I don't know. Probably just having fun.

--
Best regards,
Andrey Tarasevich
Mar 27 '08 #12
On Mar 27, 2:21 pm, Andrey Tarasevich <andreytarasev...@hotmail.com>
wrote:
However, once started, they quickly and quietly turn to deceiving the
reader by falsely presenting some ridiculous type encoding technique as
"hungarian notation". This demagogic technique is called "straw man
argument".
Maybe, but there were enough legitimate arguments in this thread to
hopefully rid the world of the scourge of HN.

Mar 28 '08 #13
On 28 maalis, 02:14, dave_mikes...@fastmail.fm wrote:
Maybe, but there were enough legitimate arguments in this thread to
hopefully rid the world of the scourge of HN.
I find HN useful in enums:

enum Dwarf_Professions {dwFIGHTER=1, dwHUNTER, dwROGUE, dwMINER,
dwARCHER, dwROCKTHROWER, dwMAX_PROF};

enum Goblin_Professions {goBARBARIAN=1, goFIGHTER, goHUNTER, goROGUE,
goTINKER, goMINER, goSHAMAN, goMAX_PROF};

How else could you make difference between goblin and dwarf
professions?
Mar 28 '08 #14
On Mar 28, 1:13*pm, Krice <pau...@mbnet.fiwrote:
On 28 maalis, 02:14, dave_mikes...@fastmail.fm wrote:
Maybe, but there were enough legitimate arguments in this thread to
hopefully rid the world of the scourge of HN.

I find HN useful in enums:

enum Dwarf_Professions {dwFIGHTER=1, dwHUNTER, dwROGUE, dwMINER,
dwARCHER, dwROCKTHROWER, dwMAX_PROF};

enum Goblin_Professions {goBARBARIAN=1, goFIGHTER, goHUNTER, goROGUE,
goTINKER, goMINER, goSHAMAN, goMAX_PROF};

How else could you make difference between goblin and dwarf
professions?
DWARF_ and GOBLIN_? The instant I saw "dw", I thought "double word".
Why use a cryptic two letter abbrev when you can use a more
descriptive word?

Mar 28 '08 #15
On 28 maalis, 20:16, dave_mikes...@fastmail.fm wrote:
Why use a cryptic two letter abbrev when you can use a more
descriptive word?
You have a point there. I guess HN is more nerdy.
Mar 28 '08 #16
LR
Krice wrote:
On 28 maalis, 02:14, dave_mikes...@fastmail.fm wrote:
>Maybe, but there were enough legitimate arguments in this thread to
hopefully rid the world of the scourge of HN.

I find HN useful in enums:

enum Dwarf_Professions {dwFIGHTER=1, dwHUNTER, dwROGUE, dwMINER,
dwARCHER, dwROCKTHROWER, dwMAX_PROF};

enum Goblin_Professions {goBARBARIAN=1, goFIGHTER, goHUNTER, goROGUE,
goTINKER, goMINER, goSHAMAN, goMAX_PROF};

How else could you make difference between goblin and dwarf
professions?
How about this?

struct Dwarf {
enum Profession {
FIGHTER=1, HUNTER, ROGUE, MINER,
ARCHER, ROCKTHROWER, MAX_PROF};
};

struct Goblin {
enum Profession {
BARBARIAN=1, FIGHTER, HUNTER, ROGUE,
TINKER, MINER, SHAMAN, MAX_PROF};
};

LR
Mar 28 '08 #17
On 2008-03-28 20:27, LR wrote:
Krice wrote:
>On 28 maalis, 02:14, dave_mikes...@fastmail.fm wrote:
>>Maybe, but there were enough legitimate arguments in this thread to
hopefully rid the world of the scourge of HN.

I find HN useful in enums:

enum Dwarf_Professions {dwFIGHTER=1, dwHUNTER, dwROGUE, dwMINER,
dwARCHER, dwROCKTHROWER, dwMAX_PROF};

enum Goblin_Professions {goBARBARIAN=1, goFIGHTER, goHUNTER, goROGUE,
goTINKER, goMINER, goSHAMAN, goMAX_PROF};

How else could you make difference between goblin and dwarf
professions?

How about this?

struct Dwarf {
enum Profession {
FIGHTER=1, HUNTER, ROGUE, MINER,
ARCHER, ROCKTHROWER, MAX_PROF};
};

struct Goblin {
enum Profession {
BARBARIAN=1, FIGHTER, HUNTER, ROGUE,
TINKER, MINER, SHAMAN, MAX_PROF};
};
Drop the all-caps and it is quite good, personally I would have liked
the enumerators to be scoped so you would have have to play with a
struct/namespace. Luckily this will be in the next standard.

--
Erik Wikström
Mar 29 '08 #18
On 29 maalis, 18:49, Andy Champ <no....@nospam.comwrote:
the other problem is what is the correct name for the Dwarf
version of the spell "ROCKTHROWER"? dw isn't enough to
distinguish them. So you end up with dwprROCKTHROWER and
dwweROCKTHROWER.
What spell?:) No I don't end up with dwpr or dwwe or anything
else than those enums.
Mar 29 '08 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Denny | last post by:
For most of my variable names, I use Hungarian notation to determine between one and the other. But what names can I use for public and private variables? I was using prv_varName and pub_varName...
28
by: Phill | last post by:
Does anyone know the reasoning for Microsoft abandoning Hungarina Notation in C#? I have found it very usefull in C++. I like this style: constant: MY_CONSTANT methos: myMethod() class: ...
66
by: CMM | last post by:
So after three years of working in .NET and stubbornly holding on to my old hungarian notation practices--- I resolved to try to rid myself of the habit. Man, I gotta say that it is liberating!!! I...
24
by: Ronald S. Cook | last post by:
An ongoing philosophical argument, I would like your opinions. With the release of .NET, Microsoft spoke of moving away from the notation as a best practice. I'm a believer for a few reasons: ...
24
by: darrel | last post by:
I just discovered that MS recommends that we NOT use hungarian notation with the .net framework: http://msdn2.microsoft.com/en-us/library/ms229045.aspx What are the real cons for using it? ...
6
by: Grey Squirrel | last post by:
On wednesday my company will have an open ended discussion whether to standardize hungarian notation or pascal/cammel case notation. We'd love to recieve some feedback on what other people are...
3
by: Grey Squirrel | last post by:
On wednesday my company will have an open ended discussion whether to standardize hungarian notation or pascal/cammel case notation. We'd love to recieve some feedback on what other people are...
3
by: Ronald S. Cook | last post by:
For all those anti-Hungarian notation people out there, how would you name an employee first name label and textbox on an create/modify employee form, respectively (please)? Thanks, Ron
12
by: inhahe | last post by:
Does anybody know of a list for canonical prefixes to use for hungarian notation in Python? Not that I plan to name all my variables with hungarian notation, but just for when it's appropriate.
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.