hungarian notation

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

hungarian notation

Postby evilbeanfiend » Thu Nov 15, 2007 1:48 pm UTC

not been done yet so i'll start it with my view

while it has a use in languages such as C e.g. differentiating between safe and unsafe strings, it doesn't have a place in any language where you can enforce that in the type system. i.e. it has its time and its place but we (mostly) don't need it any more.

commence bitchin'
in ur beanz makin u eveel

User avatar
Hammer
Because all of you look like nails.
Posts: 5491
Joined: Thu May 03, 2007 7:32 pm UTC
Contact:

Re: hungarian notation

Postby Hammer » Thu Nov 15, 2007 2:03 pm UTC

I use prefixes on names for certain things mainly as an organizational tool or to help avoid naming collisions. I never use them to indicate the type of a variable, nor do I trust it when I see it in other people's code. I always go check the declaration to determine what I have.

The database environment uses of it drive me up the wall. People prefixing their table names with tbl and form names with frm. WTF is that supposed to accomplish? Or naming your Text Box starting with txt, so that if you change it to a dropdown later you have to go update all your code because you swapped out a widget. Or, even better, you don't go change all the code.

Embedding the alterable properties of a thing in its name. Blech. * spits on floor *
"What's wrong with you mathematicians? Cake is never a problem."

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: hungarian notation

Postby rrwoods » Thu Nov 15, 2007 2:20 pm UTC

Hammer wrote:I use prefixes on names for certain things mainly as an organizational tool or to help avoid naming collisions. I never use them to indicate the type of a variable, nor do I trust it when I see it in other people's code. I always go check the declaration to determine what I have.

The database environment uses of it drive me up the wall. People prefixing their table names with tbl and form names with frm. WTF is that supposed to accomplish? Or naming your Text Box starting with txt, so that if you change it to a dropdown later you have to go update all your code because you swapped out a widget. Or, even better, you don't go change all the code.

Embedding the alterable properties of a thing in its name. Blech. * spits on floor *

This.


The only time I've ever been tempted to use hungarian for anything at all is when I need the same value as two different data types (most commonly number-based and string) and I need to keep it around. Even then, I typically just stick on "disp" or similar at the beginning of the string one rather than explicitly declaring its type with "str" or "sz" or other nonsense.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Thu Nov 15, 2007 5:37 pm UTC

On a whole, no.

But: there are some things that are inexpressible in the type system, and there it's not unreasonable. (Safe/unsafe strings are the stereotypical example of this, though there are others. There is also not a clear division. Should we use 'psz' for a pointer to a typical C string? After all, it carries strictly more information than char*. [One of these days I will get around to making that "why C strings suck" topic. ;-)] Probably this is overkill.)

The other time I feel it's useful is if you're giving a short code snippet, where you don't want to declare your variables. Often time just dropping on the appropriate prefix leads to enough clarity.

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: hungarian notation

Postby evilbeanfiend » Thu Nov 15, 2007 5:40 pm UTC

but safe and unsafe strings are expressible in the type system of some languages, my argument would be that in that case there is no need for hungarian notation at all in that language (assuming you are free to e.g. not interact with 3rd party code that insists on it)
in ur beanz makin u eveel

User avatar
davean
Site Ninja
Posts: 2498
Joined: Sat Apr 08, 2006 7:50 am UTC
Contact:

Re: hungarian notation

Postby davean » Thu Nov 15, 2007 5:46 pm UTC

EvanED wrote:On a whole, no.

But: there are some things that are inexpressible in the type system, and there it's not unreasonable. (Safe/unsafe strings are the stereotypical example of this, though there are others. There is also not a clear division. Should we use 'psz' for a pointer to a typical C string? After all, it carries strictly more information than char*. [One of these days I will get around to making that "why C strings suck" topic. ;-)] Probably this is overkill.)

The other time I feel it's useful is if you're giving a short code snippet, where you don't want to declare your variables. Often time just dropping on the appropriate prefix leads to enough clarity.


Actually, I express that with the type system all the time, I also express escaped/escaped and confidential/non confidential. I use it as part of my embedded proof of correctness system. Its a really easy thing to do in any language with even a half decent type system.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: hungarian notation

Postby Yakk » Thu Nov 15, 2007 5:49 pm UTC

You also need an IDE that makes the type of variables easy to find.

And then there are things that languages don't provide. Ie, I append _ onto the end of constructor arguments that are going to be used to initialize the member variable of the same name. This has extended to a convention of "_" at the end means an unchanged parameter to a method which will be munged and turned into a local variable in the function of the same name, but possibly of slightly different type, but the same meaning.

So:

Code: Select all

foo(bool* error_) {
  bool tmp = false;
  bool& error = error?*error_:tmp;
  ...
  if (things are screwed up) {
    error = true;
    return;
  }
}

might be a crude example of such an effect. The error parameter and the error internal variable have the same "goal" or "use", but the parameter is left unchanged (and possibly null), while the munged local variable can be changed. (And yes, it should be bool*const error, but I figured that might confuse at least 1 person, and wasn't worth it. And yes, there are better ways to do the above trick, and I've often moved over to them).

In this case, the error parameter is an optional error return flag. The caller can pass in a pointer to a bool or a null pointer. If you pass in a null pointer, you don't get back error information (and sometimes you don't want error information: you just want to try something and if it doesn't work, you ain't gonna change the rest of your plans...)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Thu Nov 15, 2007 5:49 pm UTC

evilbeanfiend wrote:but safe and unsafe strings are expressible in the type system of some languages, my argument would be that in that case there is no need for hungarian notation at all in that language (assuming you are free to e.g. not interact with 3rd party code that insists on it)

Yes, exactly.

The full weight of hungarian notation made sense in BCPL for instance. This is the land where it was developed, because, AFAIK, BCPL doesn't check type information. (I'm not 100% sure what this means.) So even things like "this is a word, so call it wStuff" aren't really redundant with type information. Moving to C means that the compiler knows the type, so calling it wStuff becomes fully redundant. Same deal with the sz sytax: it carries information in C, but you wouldn't use it to mark a string in a language that supports strings as a first-class type.

That said, the most common languages in use now don't really support the ability to put that into your typesystem without some effort (e.g. create a whole new wrapper class then write all the functions for it), or external tools (*cough* CQual *cough*). The only semi-exception to that is C++, where you can somewhat fake opaque typedefs, but even that gets pretty ugly.

And in an interesting cycle, we've almost come full circle with the increasing popularity of "dynamically typed"/untyped languages like Python, back to the point where, IMO, including more type information in variable names makes at least some sense.

davean wrote:Actually, I express that with the type system all the time, I also express escaped/escaped and confidential/non confidential. I use it as part of my embedded proof of correctness system. Its a really easy thing to do in any language with even a half decent type system.


How do you mark the difference between types strings in, say, C?

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: hungarian notation

Postby evilbeanfiend » Thu Nov 15, 2007 6:00 pm UTC

EvanED wrote:That said, the most common languages in use now don't really support the ability to put that into your typesystem without some effort (e.g. create a whole new wrapper class then write all the functions for it)


meh, you only need to write the boiler plate stuff once, save you from repeatedly writing horrible notation and guarantees you can't make a mistake. seems worth it to me.
Last edited by evilbeanfiend on Thu Nov 15, 2007 6:05 pm UTC, edited 1 time in total.
in ur beanz makin u eveel

User avatar
davean
Site Ninja
Posts: 2498
Joined: Sat Apr 08, 2006 7:50 am UTC
Contact:

Re: hungarian notation

Postby davean » Thu Nov 15, 2007 6:04 pm UTC

EvanED wrote:
davean wrote:Actually, I express that with the type system all the time, I also express escaped/escaped and confidential/non confidential. I use it as part of my embedded proof of correctness system. Its a really easy thing to do in any language with even a half decent type system.


How do you mark the difference between types strings in, say, C?


C doesn't have even a half assed type system. In C++ though it is just a little bit of template meta programming to be able to compose the types of your dreams on the fly.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Thu Nov 15, 2007 6:07 pm UTC

So what about Java? Does it have a half-decent type system? And how would you do it there?

User avatar
davean
Site Ninja
Posts: 2498
Joined: Sat Apr 08, 2006 7:50 am UTC
Contact:

Re: hungarian notation

Postby davean » Fri Nov 16, 2007 6:00 am UTC

You'd probably need wrapper classes. Java didn't but it got a lot of stuff fixed with Generics and the like, I'd hope it does now but I haven't looked in a while.

photosinensis
Posts: 163
Joined: Wed Aug 22, 2007 6:17 am UTC

Re: hungarian notation

Postby photosinensis » Fri Nov 16, 2007 6:17 am UTC

If a coder is using Hungarian notation, s/h/it must be retarded. Even in type unsafe (or untyped) languages, one must ask why you're doing such silly things. Honestly, the whole thing reminds me of generics in Java.
While I clicked my fav'rite bookmark, suddenly there came a warning,
And my heart was filled with mournng, mourning for my dear amour.
"'Tis not possible!" I uttered, "Give me back my free hardcore!"
Quoth the server: 404.

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: hungarian notation

Postby evilbeanfiend » Fri Nov 16, 2007 2:02 pm UTC

davean wrote:You'd probably need wrapper classes. Java didn't but it got a lot of stuff fixed with Generics and the like, I'd hope it does now but I haven't looked in a while.


there is nothing to stop you actually writing wrappers around any class you need without templates/generics anyway, its just you need to repeat the boiler plate code for each new type.
in ur beanz makin u eveel

User avatar
pieaholicx
The cake is a lie!
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC
Contact:

Re: hungarian notation

Postby pieaholicx » Fri Nov 16, 2007 2:14 pm UTC

I agree that using it is stupid. If I have to change a variable name just because of a type change then I've wasted more time then is necessary. From a completely profit standpoint, my engineers just changed the type of one variable, so they now have to spend time that could be used for progress for changing that variable name.

However, in exchange for not using the system I think that meaningful variable names should be used. Ones where you can make a good guess about the type just from the name.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.

User avatar
iop
Posts: 930
Joined: Tue Jul 24, 2007 11:26 am UTC
Location: The ivory tower

Re: hungarian notation

Postby iop » Fri Nov 16, 2007 2:27 pm UTC

Since I do a lot of my programming in Matlab, where you don't declare types, I do use it at times, especially with variables containing indices (though I find it more natural to use suffixes). dataOutlierIdx would contain linear indices into data, while dataOutlierIdxL would be a logical index with the same size as data.

User avatar
davean
Site Ninja
Posts: 2498
Joined: Sat Apr 08, 2006 7:50 am UTC
Contact:

Re: hungarian notation

Postby davean » Fri Nov 16, 2007 5:57 pm UTC

evilbeanfiend wrote:
davean wrote:You'd probably need wrapper classes. Java didn't but it got a lot of stuff fixed with Generics and the like, I'd hope it does now but I haven't looked in a while.


there is nothing to stop you actually writing wrappers around any class you need without templates/generics anyway, its just you need to repeat the boiler plate code for each new type.


No, without generics you had issues with type consistency and casting in generic containers. Mind you, there where lots of other breaks in the type system also.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: hungarian notation

Postby rrwoods » Fri Nov 16, 2007 6:33 pm UTC

You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around. What issues are you talking about that generics happened to solve -- just the general "I have to cast everything" issue?
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Fri Nov 16, 2007 6:48 pm UTC

rrwoods wrote:You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around.

Yeah, it's an unfortunate property. Seems like it should work... but no.

What issues are you talking about that generics happened to solve -- just the general "I have to cast everything" issue?

Well, either you don't realize the importance of this, are seemingly trivializing the importance by your wording, or don't think it's nearly as important as I do.

It's not just a matter of code prettyness or readability: it's a matter of static type safety. If I have a list<Integer> and do Integer i = list.get(0); (I'm abusing notation and maybe names a little here), I know that will work out. If I have an unspecialized list and do Integer i = (Integer) list.get(0);, not only is the code a little uglier, but there is a possibility of a runtime failure. And if it does fail, the error is where I'm putting an non-Integer into the list, so I have to figure out where that occurs, and in general there is no direct way to do this.

(Me likes static safety. Hey, maybe that's a thread the mods should bring over here. Oh, and the tabs vs. spaces one from coding...)

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: hungarian notation

Postby Rysto » Fri Nov 16, 2007 6:57 pm UTC

rrwoods wrote:You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around.

Java actually gets this one right. List<Derived> is a List<? extends Base>, and the upshot of this is that you can get Bases out of a List<? extends Base> but you can't put Bases into one.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Fri Nov 16, 2007 7:01 pm UTC

Rysto wrote:
rrwoods wrote:You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around.

Java actually gets this one right. List<Derived> is a List<? extends Base>, and the upshot of this is that you can get Bases out of a List<? extends Base> but you can't put Bases into one.

Generics are sorta weird. I should look into them in more detail sometime, I only know the surface bits because the times I've done Java work have been either (1) before Java 5 was released period, or (2) before a Java 5 JVM had been released for the target platform (*cough* S/390 Linux *cough*).

I know C++ templates pretty well now, and generics can't possibly be that ugly... ;-)

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: hungarian notation

Postby rrwoods » Fri Nov 16, 2007 8:08 pm UTC

EvanED wrote:are seemingly trivializing the importance by your wording
That one.

I have a bad habit of doing this... possibly continuing to converse on this forum will help to break me of that habit.

By "I have to cast everything" I pretty much meant everything in your post.

Rysto wrote:
rrwoods wrote:You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around.

Java actually gets this one right. List<Derived> is a List<? extends Base>, and the upshot of this is that you can get Bases out of a List<? extends Base> but you can't put Bases into one.

I have yet to learn the ins and outs of the "?" notation for generics, so in most cases, I find myself in the "I want to pass a List-of-D to a function that accepts a List-of-B" situations.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: hungarian notation

Postby Yakk » Fri Nov 16, 2007 8:17 pm UTC

Generics allow compile-time duck-type checking of type contracts. (or not-duck)

That is, well, extremely powerful. And it is more than just "saving the bother of casting" -- sometimes your things are not inter-castable, yet have the same duck-type. And sometimes you don't even have access to the entire list of types which satisfy your duck-type when you write your code. (Duck-type: it walks like a duck, it quacks like a duck).

...

They also allow you, in C++, to automate a bunch of code generation in-language.

I can make decisions based on types or compile-time parameters passed, and generate different code depending on the compile-time arguments.

Using some tricks, I can do queries about the features of the types passed to the code.

So when given two pointers, and asked how far apart they are, I can subtract. When given two list iterators, I can walk the distance between them. When given two tree iterators, I can climb the tree and count that way.

More fancy, different types could have different meanings of "assign" which involve different steps.

Or my code might follow different optimization branches based on template arguments. I can generate quadratic or greater code output from a linear amount of typing.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: hungarian notation

Postby Rysto » Fri Nov 16, 2007 8:32 pm UTC

Yakk wrote:Generics allow compile-time duck-type checking of type contracts. (or not-duck)

That is, well, extremely powerful. And it is more than just "saving the bother of casting" -- sometimes your things are not inter-castable, yet have the same duck-type. And sometimes you don't even have access to the entire list of types which satisfy your duck-type when you write your code. (Duck-type: it walks like a duck, it quacks like a duck).

Not in Java. In Java you must use interfaces to enforce this.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: hungarian notation

Postby Yakk » Fri Nov 16, 2007 9:03 pm UTC

Yeuch. And I presume there is no way to state "to make class X match interface Y, use the following munge"?
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: hungarian notation

Postby Rysto » Fri Nov 16, 2007 10:05 pm UTC

Yakk wrote:Yeuch. And I presume there is no way to state "to make class X match interface Y, use the following munge"?

You have to code it explicitly using the adapter pattern.

LauraSakura
Posts: 18
Joined: Fri Feb 22, 2008 3:16 pm UTC
Location: Somewhere between Azeroth and Middle Earth

Re: hungarian notation

Postby LauraSakura » Fri Feb 22, 2008 3:53 pm UTC

I use it in Visual Basic.
For me, it helps keep me organized and remember what is what.

User avatar
segmentation fault
Posts: 1770
Joined: Wed Dec 05, 2007 4:10 pm UTC
Location: Nu Jersey
Contact:

Re: hungarian notation

Postby segmentation fault » Fri Feb 22, 2008 5:55 pm UTC

rrwoods wrote:You still have some issues with type consistency in generic containers. A container-of-derived isn't a container-of-base, which is always hard for me to re-wrap my head around.


that sort of enforces type consistency, no?

inheritance (within c++ at least) only allows for you to access Derived classes using a pointer-to-Base. you shouldnt use it any other way. in other words, your container of Derived must have derived classes inserted, but you can iterate through using a pointer to Base. in addition, if you have a container of pointer-to-Base, you can have them point to any classes that are derived from Base.

as for hungarian, i see no need for it. it only confuses me further, and if you need to determine between strings that are zero terminated and strings that arent, well i want nothing to do with it.
people are like LDL cholesterol for the internet

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: hungarian notation

Postby Sc4Freak » Sat Feb 23, 2008 3:43 am UTC

Hungarian notation had its place in the world, once. It can be moderately useful in C, and when you don't have a good IDE. That's why all of Microsoft's old code uses Hungarian notation. With the advent of better IDEs (<3 Visual Studio), the type of a variable can be determined by hovering over the variable name with the mouse. That's why I believe systems Hungarian is obsolete. Microsoft thinks so, too.

I try to avoid variable prefixes. But when naming my types, I like to prefix my concrete classes with "C", and my interfaces with "I". A lot of my old code uses this, too, so it's not worth the trouble to change it anyway.

When I have a constructor, I have a bad habit of shadowing my class members with the parameters. Since I use initialiser lists a lot, this isn't a problem. And for types that don't have a constructor, I use "this" to resolve the conflict..

Code: Select all

CFoo::CFoo(int Bar, const RECT& Baz) : Bar(Bar)
{
    this->Baz.left = Baz.left;
    // etc.
}

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Sat Feb 23, 2008 10:29 am UTC

Sc4Freak wrote:Hungarian notation had its place in the world, once. It can be moderately useful in C, and when you don't have a good IDE. That's why all of Microsoft's old code uses Hungarian notation. With the advent of better IDEs (<3 Visual Studio), the type of a variable can be determined by hovering over the variable name with the mouse. That's why I believe systems Hungarian is obsolete. Microsoft thinks so, too.

Personally, I think at least a strong argument can be made for its resurgence with dynamically typed languages. I don't program in them nearly enough to weigh seriously into the issue though.

Pretty much the only hungarianish notation I use on a regular basis are things like "nBlahs" for the number of something.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: hungarian notation

Postby Rysto » Sun Feb 24, 2008 2:24 am UTC

Personally, I think at least a strong argument can be made for its resurgence with dynamically typed languages. I don't program in them nearly enough to weigh seriously into the issue though.

That's one way of looking at it. Another is that it's a strong argument against dynamically-typed languages. :D

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: hungarian notation

Postby Berengal » Sun Feb 24, 2008 4:26 am UTC

Rysto wrote:
Personally, I think at least a strong argument can be made for its resurgence with dynamically typed languages. I don't program in them nearly enough to weigh seriously into the issue though.

That's one way of looking at it. Another is that it's a strong argument against dynamically-typed languages. :D

Rather, dynamically-typed languages are a strong argument against hungarian notation.

When I first started coding (in NWScript) I used it, because everyone else did. Or at least the declarations that came up in the bottom of the IDE did. It sort of made sense there, and I never encountered any problems with it, although most of the time it was really redundant.
These days I never use it anymore, prefering to write variable names out fully. Sometimes I'll go "nrPeople" instead of "numberOfPeople", but unless there's an easy and most importantly common abrevation for something I'll use the full name. I especially won't tack on just a single letter that could mean anything.

I do however use single-letter variable names for really short lived varaibles. I do "for(int i..." all the time, as well as "for(Person p: people)". These only happen in scopes I can display fully on my cellphone, however, so shouldn't provide any problems.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Sun Feb 24, 2008 10:11 am UTC

Berengal wrote:Rather, dynamically-typed languages are a strong argument against hungarian notation.

Please justify?

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: hungarian notation

Postby Yakk » Sun Feb 24, 2008 3:25 pm UTC

I can think of two strong arguments why Hungarian notation and Dynamic typing are ... sort of silly together.

If Dynamically Typed features are The Be All and End All, then Types Are Bad! Why do you need types? That is why you are using a Dynamically Typed language. Giving a variable name a pseudo-type via Hungarian notation is a crappy typing system, which we have already established as being a bad thing.

Conversely, if you need hungarian notation in a Dynamically Typed only language, then you are in effect adding a type system to the language. In which case, you should be using a typed language that has the other features of the language, rather than using the crappy C-era variable name typing system.

:)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Aperfectring
Posts: 252
Joined: Fri Sep 07, 2007 3:47 am UTC
Location: Oregon (happily)

Re: hungarian notation

Postby Aperfectring » Sun Feb 24, 2008 11:24 pm UTC

Honestly, I think that if your function is long enough that you need to use hungarian notation to remember the type, then your code needs a redesign. Your keyboard has a pgup and pgdwn key for a reason, and if the top of your function (declarations) is more than a few (3-5 at most) pg key presses away, something tells me your function is trying to do to much, and should probably be broken up into multiple functions.

With large classes, you should have either a second window or pane, or printout up with the class definition so that you can quickly find the types of members/functions.

The only possible exception to the few pg key presses system is if you are in a performance critical situation, and then your code is probably confusing enough that you need to have more comments than code, and you can name the types (if needed) of the variables in the comments.

Now for the disclaimer: I generally do systems programming where using anything other than primitive types is rare. Generally the only time I use something other than a pointer, integer (of some size), or C-style string is when we create an API which has a structure as an input, to have less arguments. Now this still can create questions of type, in that the size of an integer can sometimes have large implications, however, most of the time, functions are fairly short.
Odds are I did well on my probability exam.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Sun Feb 24, 2008 11:34 pm UTC

Aperfectring wrote:Honestly, I think that if your function is long enough that you need to use hungarian notation to remember the type, then your code needs a redesign. Your keyboard has a pgup and pgdwn key for a reason, and if the top of your function (declarations) is more than a few (3-5 at most) pg key presses away, something tells me your function is trying to do to much, and should probably be broken up into multiple functions.

Hungarian wouldn't be for you as you're developing the function (at least the way I'm thinking about it)... it would be used in the method interface so that when code assist tools show you the arguments to a function, the expected "types" are there.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: hungarian notation

Postby Yakk » Sun Feb 24, 2008 11:36 pm UTC

... your code assist tools don't display the types of the function? (or, in a language lacking types, some markup related to each variable?)
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

coppro
Posts: 117
Joined: Mon Feb 04, 2008 6:04 am UTC

Re: hungarian notation

Postby coppro » Mon Feb 25, 2008 12:08 am UTC

Yakk wrote:... your code assist tools don't display the types of the function? (or, in a language lacking types, some markup related to each variable?)
There are people (myself included) that don't use IDEs or any other sort of code assist system. I've never really found them to be worth the effort, since I don't really like VIM or Emacs (this makes me a heretic, I know), IDEs generally suffer from a lack of flexibility (if only Doxygen were faster), and generally, the functions I'm calling fall in to two categories - functions in the project I'm working on, and so should have the file open anyway because it's fair game for editing (and often, editing them is necessary), or functions with documentation, in which case I should have the documentation open (if I'm extra-lucky, I have both). And in both cases, simply knowing the type/params of a function isn't enough - there might be another function that can do it faster, and an IDE can't help you with that.

But I don't like Hungarian notation, because if you can remember the name of the variable, you should be able to remember it's type. And good programmers can name variables such that you know what they are anyway. I mean, could you think that the return type of count() could be anything non-integral?

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: hungarian notation

Postby EvanED » Mon Feb 25, 2008 1:18 am UTC

Yakk wrote:... your code assist tools don't display the types of the function? (or, in a language lacking types, some markup related to each variable?)

For a dynamically-typed language, no, it doesn't display the type. ;-) (I'm not sure what other markup you would get.)

(Also, keep in mind that you should be taking what I say with a grain of salt. I am not completely confidant in what I'm saying.)

coppro wrote:But I don't like Hungarian notation, because if you can remember the name of the variable, you should be able to remember it's type. And good programmers can name variables such that you know what they are anyway. I mean, could you think that the return type of count() could be anything non-integral?

To some extent, yes, this is true. But what kind of int? What size? Signed or unsigned? Knowing what it returns might affect the code you write so that you avoid compiler warnings. And not all functions are as clear.

User avatar
Sc4Freak
Posts: 673
Joined: Thu Jul 12, 2007 4:50 am UTC
Location: Redmond, Washington

Re: hungarian notation

Postby Sc4Freak » Mon Feb 25, 2008 12:34 pm UTC

coppro wrote:
Yakk wrote:... your code assist tools don't display the types of the function? (or, in a language lacking types, some markup related to each variable?)
There are people (myself included) that don't use IDEs or any other sort of code assist system. I've never really found them to be worth the effort, since I don't really like VIM or Emacs (this makes me a heretic, I know), IDEs generally suffer from a lack of flexibility (if only Doxygen were faster), and generally, the functions I'm calling fall in to two categories - functions in the project I'm working on, and so should have the file open anyway because it's fair game for editing (and often, editing them is necessary), or functions with documentation, in which case I should have the documentation open (if I'm extra-lucky, I have both). And in both cases, simply knowing the type/params of a function isn't enough - there might be another function that can do it faster, and an IDE can't help you with that.

That's true, but irrelevant. The fact that an IDE can't choose your function for you isn't an indication that not using an IDE is better than using one. If I'm using an API I'd have its documentation open anyway, regardless of whether I'm using an IDE or not. However, the IDE is able to convey fast type information as I type. Rather than switch to the documentation for type information (for example, to find out whether the function requires a pointer or a reference), the IDE will tell me what types are required as soon as I type the function name.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 4 guests