Click here to Skip to main content
15,358,692 members

Welcome to the Lounge


For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

QuestionRe: Why the world hates Hungarian notation? Pin
MSBassSinger5-Apr-12 5:17
professionalMSBassSinger5-Apr-12 5:17 
GeneralRe: Why the world hates Hungarian notation? Pin
SeattleC++5-Apr-12 6:00
MemberSeattleC++5-Apr-12 6:00 
GeneralRe: Why the world hates Hungarian notation? Pin
Member 37636085-Apr-12 6:58
MemberMember 37636085-Apr-12 6:58 
GeneralRe: Why the world hates Hungarian notation? - Data Dictionary Pin
Toyist5-Apr-12 7:02
MemberToyist5-Apr-12 7:02 
GeneralRe: Why the world hates Hungarian notation? Pin
Mark Johnston (SSCGP)5-Apr-12 7:30
MemberMark Johnston (SSCGP)5-Apr-12 7:30 
GeneralRe: Why the world hates Hungarian notation? Pin
we785-Apr-12 7:56
Memberwe785-Apr-12 7:56 
GeneralRe: Why the world hates Hungarian notation? Pin
jschell5-Apr-12 9:15
Memberjschell5-Apr-12 9:15 
GeneralRe: Why the world hates Hungarian notation? Pin
Ed Hastings5-Apr-12 9:36
MemberEd Hastings5-Apr-12 9:36 
It's a subjective preference of course, so there's not absolute reason(s). Back in the day I used Hu notation; we pretty much all did when it was the "thing you should do".

However, here are some points that collectively tilt the scale towards not using Hu these days.

* Hu originally solved a problem, the difficulty of quickly differentiating typed variables in primitive development environments.

However the modern use of more powerful IDE's having more robust intellisense or similar capabilities that make it trivial to "see" applicable metadata about variables (etc) addresses the need for a quick means of figuring out what is what.

Though you say you like to take snippets of logic to review in a simple text editor rather than "have the entire project" local and use your IDE of choice, I would think that you are an exception. Using source repositories it is trivial and normal to have a copy of all source on your workstation or laptop, to work "disconnected", and to synch delta on either side up with the repository when connected and you wish to. I'm not sure what benefit you would gain from working with snippets in a "dead" environment, when it is so easy to work on a compilable, runnable local version.

For that matter, these days the source repository is generally only a VPN connection away unless you are on the road or in the air in most corporate environments.

This usage of snippets to take home may be an old habit of yours that bears reevaluation; maybe it's no longer necessary.

* In the style of OOP currently en vogue, injection is often favored. Many things that used to be variables are often parameters or properties now.

Any localized variables tend to be very localized, as in declared very close to their usage, and at method scope or even less (lambdas, etc).

Short, concise methods are greatly preferred over long rambling ones, making it much more likely that variable declaration is in close proximity to its usage.

* Refactoring is commonly practiced, ideally altering implementation while maintaining functionality. What is a double today might be an int tomorrow; a string might become a char[] or vice versa. Ideally the name shouldn't need to change.

Related to this, is the consideration of once and only once; if the name of a variable contains some token or segment that is a direct reinstatement of its (original) underlying type, you have effectively duplicated the information. If the underlying type changes, the "duplication" of the original type information should also change, but might not causing a classic information synching issue.

* In C#, the usage of the var key word and type inference at compile time is a pretty useful feature, but would not cooperate very well with Hu notation.

Something like:

var intResult = SomeMethod(...);

is obviously kind of silly...especially if SomeMethod(...) later gets refactored to return int? vs int, or any other type at all.

Also...what is the Hu notation for a nullable primitive?

int? nintResult;
int? n_intResult;
int? nIntResult;

Not loving that idea.

* .NET and C# in particular takes some pains to smooth the differences between value types and reference types, and encourages you to use an instance of a primitive object on the stack similarly to an instance of a reference type on the heap aside from the obvious localized scoping of changes to value types. As complex types tend to be much more common in most applications, naming conventions have evolved to tend to favor complex types more than primitive types.

Complex types with camel cased names like MyVerySpecialClass : MyVeryAbstractBase Hu oddly if you are of a very literal bent...

MyVeryAbstractBase mvabSubclass = new MyVerySpecialClass();

Early on in .NET, and this seemed to be encouraged by MS based on writings and examples of the time, tended to just use a sort of acronymization in a kind of vague Hu, something like this:

MyVeryAbstractBase mvab = new MyVerySpecialClass();

or, vexingly, an implicit assumption of specific concreteness such as:

MyVeryAbstractBase mvsc = new MyVerySpecialClass();

of more irritating, unnecessary concrete declaration:

MyVerySpecialClass mvsc = new MyVerySpecialClass();

This habit seems to be falling away finally, though it still seems to crop up in throw away variables in for's, foreaches, and lambdas where the brevity is basically harmless due to the very narrow scope (though I still prefer clear, full names).

Having one naming convention for primitives (Hu, for instance), and a different naming convention for complex types (PascalCase, for instance) works against the efforts made to unify usage of both.

Having said all of that, the MS Press Framework Design Guidelines book has a a couple of pages on Hungarian notation and why it is restricted / discouraged in .NET.

A key point is, privately scoped members are not held to the same rigor as non-privately scoped members. If you want to name all your private variables using Hu, then only the other people on your team or future devs who land on your code base later are going to care.

Another key point is the main value of conventions is consistency. It's better to be consistent and "wrong" per current prevailing mores, that it is to inconsistently adhere to them. Personally I find this to be a mark against Hu as it is more difficult to remain consistent over time if underlying data types change, but still.

Personally...the only place I still use Hu notation is in designer / template centric environments such as .aspx web pages where type declarations are effectively split between the template and the backing object.

Thus, I find a prefixed notation like this to be handy:

<asp:textbox runat="server" id="tbSalutation" ...="">
<asp:textbox runat="server" id="tbUserName" ...="">

...SomeBackingBindMethod(SomeDataRecord record)
if(record == null) return;
tbUserName.Text = record.UserName;
tbSalutation.Text = record.Salutation;

There is a nice secondary benefit of having an immediate mnemonic of what sort of control object I'm dealing with without needing to look at the designer as often, but the MAIN benefit the prefix gives me is that it naturally groups similar types of control for intellisense usage.

I don't have to remember the exact name of every textbox or checkbox or label; I can just type "tb..." and intellisense gives me an assist by painting a type down list of all the textboxes thus prefixed allowing me to hone in on the one I want quickly.

This is very pragmatic in my opinion, and also helps bridge the gap between OOP and parsed / merged view templates.
AnswerRe: Why the world hates Hungarian notation? Pin
RiskFactor5-Apr-12 11:32
MemberRiskFactor5-Apr-12 11:32 
GeneralRe: Why the world hates Hungarian notation? Pin
Gerry Schmitz6-Apr-12 14:37
mveGerry Schmitz6-Apr-12 14:37 
GeneralRe: Why the world hates Hungarian notation? Pin
john morrison leon9-Apr-12 4:06
Memberjohn morrison leon9-Apr-12 4:06 
GeneralRe: Why the world hates Hungarian notation? Pin
Stefan SeelandOld30-Apr-12 1:25
MemberStefan SeelandOld30-Apr-12 1:25 
GeneralRe: Why the world hates Hungarian notation? Pin
Eytukan2-May-12 21:44
MemberEytukan2-May-12 21:44 
JokeThis girl came up to me today ... PinPopular
Nagy Vilmos4-Apr-12 3:19
professionalNagy Vilmos4-Apr-12 3:19 
GeneralRe: This girl came up to me today ... Pin
Nish Nishant4-Apr-12 3:23
sitebuilderNish Nishant4-Apr-12 3:23 
GeneralRe: This girl came up to me today ... Pin
Henry Minute4-Apr-12 5:24
MemberHenry Minute4-Apr-12 5:24 
GeneralRe: This girl came up to me today ... Pin
Nish Nishant4-Apr-12 5:29
sitebuilderNish Nishant4-Apr-12 5:29 
GeneralRe: This girl came up to me today ... Pin
Nagy Vilmos4-Apr-12 5:42
professionalNagy Vilmos4-Apr-12 5:42 
GeneralRe: This girl came up to me today ... Pin
Henry Minute4-Apr-12 3:29
MemberHenry Minute4-Apr-12 3:29 
GeneralRe: This girl came up to me today ... Pin
Mike Hankey4-Apr-12 3:35
professionalMike Hankey4-Apr-12 3:35 
GeneralRe: This girl came up to me today ... Pin
Xiangyang Liu 刘向阳4-Apr-12 3:43
MemberXiangyang Liu 刘向阳4-Apr-12 3:43 
GeneralRe: This girl came up to me today ... Pin
Marc A. Brown4-Apr-12 5:09
MemberMarc A. Brown4-Apr-12 5:09 
GeneralRe: This girl came up to me today ... Pin
Gary Wheeler4-Apr-12 7:32
MemberGary Wheeler4-Apr-12 7:32 
GeneralI was thinking of getting one of those Nokia 900 Lumias Pin
Henry Minute4-Apr-12 3:18
MemberHenry Minute4-Apr-12 3:18 
GeneralRe: I was thinking of getting one of those Nokia 900 Lumias Pin
Mike Hankey4-Apr-12 3:36
professionalMike Hankey4-Apr-12 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Straw Poll

Do you take a development machine with you on holidays?
A laptop, a mini PC, a tablet that allows you to remote to a Virtual Desktop. There are options.
  Results   675 votes