- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Hungarian notation is NOT about writing "dteDueDate" to indicate that your date really is a date, or writing intOffsetX to indicate that this is really an int.
Hungarian is about encoding useful information into a variable name. For example you could have distances expressed in centimeters and in inches.
"cmTotalDistance = cmFirstPart + inchSecondPart" is immediately understood to be wrong. Your compiler won't help you there.
Admin
To each their own. But to some it seems to be a religion. This is worse than Mac vs. Windows vs. Linux:-) Did we have any comments about other aspects of todays WTF at all?
I've worked on code with and without hungarian notation. I like the scope prefixes, beeing able to see at a glance if it's a member, a global or a static variable. I guess I could live without the type prefixes and I never do the really long multiple composite prefixes.
If I'm in someone elses code without hungarian, then I won't use it, no biggie.
Admin
On Hungarian notation:
Having 100 variables that all start with int makes intellisense a sad panda.
Admin
What you describe is possibly helpful, but it ain't Hungarian notation. You are redefining the term.
Admin
I'd argue most good programmers do that already: they just might do it in a slightly more readable way, because nobody cares about lengths of variables so much anymore, now that we have autocomplete and more-than-80-characters-wide screens.
(On the other hand, I think his dislike of exception-handlers is dumb.)
Admin
TRWTF is that everyone who commented on this article only cared about the "issue" of hungarian notation. :(
Seriously, over it man...
Admin
"Suspends UI redraw rather than use asynchronous UI and callbacks"? This is stone age pre-.net Visual Basic, no? Could such a thing even be done using that toolset?
Admin
Taking code that used Hungarian Notation dates itself to the past and then applying todays logic to it for not using asynchronous is TRWTF
Admin
Using comments as version control is something that is industry wide practice in US of A. I have seen this many times in my own code as well as coed I inherited from others.
Admin
And it's often done by clueless retards who don't understand the point of version control. My last job had a dude (old VB guy) who would litter the code with this crap; change logs, comments stating what bug was fixed, and the occasional "No clue why this is here but removing it breaks things :(" comment.
When I asked him why he didn't put those in SVN, he gave some BS answer about it being easier to see the comment/note in code instead of having to hunt through the logs.
Admin
Most programmers misundestand Hungarian Notation. It was never meant to indicate the type of the variable, but its unit. For example: dxLength1 is the distance in the x-direction, and dyLength2 is the distance in the y-direction. If you then add dxLength1 and dyLength2, it is immediately apparent that the two numbers don't add up. Hungarian Notation is a life-saver when you need to calculate engineering-units.
Admin
Spanish flu Dutch comfort German measles Chinese ace Russian roulette Hungarian notation
Admin
I could go for a ride on a g string airline
Admin
Admin
Admin
Ahh - magic text strings!
I have been hit by that too. I took over a system created by non-English speakers that for some reason had decided it was a good idea to log messages in English.
Unfortunately, they did not use spell-checkers when creating the messages, and they had a total disregard for minor details such as starting sentences with uppercase, use a space after comma, and finish the message with a full stop.
I started fixing that when I came across such ugliness and soon the system started to leak left and right. It turned out that other parts of the system relied on those log messages for displaying statuses and for triggering events. And of course that part of the code did not recognize the reformatted log messages.
So now the code has been sprinkled with warnings like
// OBS: Magic finish message. Used by MasterRouter to start processing the file.
and // OBS: Magic size message. Used by ReportPreparation when when collecting event information.
Admin
How big is your monitor?
Admin
Partly I agree with the old guy. Speed of checking comments in code is much higher than sifting through subversion comments and trying to find out what is happening.
Also another bad practice, which I like is comment out old code and keep it there. We have java servlets that contain pages and pages of commented code. then we know what took place on 1-Apr-2006 that caused the code to change.
Some comments are also colourful with email messages in them.
/* Mail from John **Jun,30, 2008 We want to bypass this condition where it checks for specific branches. Don't care about report loading time. Make it happen.
*/
Admin
Not that I want to try to justify any of that mess but when I see the word "airline" I think "screen-scraping 3rd-party apps" and in that case, it might well be that the word "Complete" is a trigger word for something else.
It's still a steaming pile when you could use some kind of event notification/generic pub-sub/MQ/whatever if you need interop.
Admin
I'm ahead of the game: I use my own personal reverse-Hungarian notation. Any object that I don't really want to keep around ends in either "foo" or "bar." So there!
Admin
I bet I'm getting Whooshed here, but that's "CamelCase." "Cameltoe" is a rather different, NSFW topic.
Admin
Damn kids that don't know how to code down to the bare hardware
Do some VMS macro programming... you will love it that DEC named things they way they did.
3 letter facility name, $ datatype _ name
for example
CIA$L_FAILLOGINCOUNT
CIA - Central intrusion App
L a longword
Admin
Next time someone tells me to do something stupid, I am SO going to do this !
Admin
I'm not a big fan of Hungarian Notation, but many of the criticisms are unconvincing to me. Funny that I can agree with you but totally disagree with many of your reasons.
"If you need to scroll more than 50 lines up or down to see the type of your variable, you're doing something wrong."
Really? When you're reading code, you continually scroll up searching for the declaration of a variable, and then scroll back down to where you were, see the next variable, scroll up searching for a declaration, etc? That seems like an awfully awkward process. Even if you find it within 50 lines or so, that's a lot of scrolling up and down.
RE tooltips in the IDE: Okay, that's way less of a pain than scrolling up and down. But (a) It assumes that you have an IDE with such a feature and you always use it when reading code, and never, e.g. read code in vi or from a print-out; and (b) It's still distracting to have to be mousing all over the place when trying to read code.
As I say, I rarely use Hungarian Notation, but I can see the argument for it: It means the type information is all right there: you just read it, you don't have to look for it.
There is one circumstance where I do use HN or HN-like notation: When the same logical value is stored in different formats or different structures.
Example 1:
In such cases, HN makes very clear what we are doing and which is which.
Example 2:
Again, the control is closely associated with the text value that we will read from or write to the control. It makes good sense to give them names which only differ in a prefix or suffix that identifies which is the string (or int or whatever) and which is the control.
RE the type may be a lie and thus gives only a false sense of security:
Sure. But you can say that about any variable name. If I see a variable called "customerName", it's possible that it really contains the zip code and the original programmer is lying to me. Indeed, while that example is extreme, I've read plenty of programs where variable names are misleading. The solution to that is to not lie when naming variables, not to deliberately remove information from variables names to avoid the possibility that the information might be wrong.
I had a job once where IT management announced a new standard that in the future all program names must be sequence numbers. (With a prefix identifying what environment they ran in -- like Web vs GUI -- and what language they were written in.) So we had program names like NBC1057 and IOF3298. Of course the programmers objected that this made it very difficult to keep track of which program was which. Management's response was that a program name could never tell you exactly what the program did and might be misleading. So ... because a name can't be guaranteed to be complete and accurate, we should make it totally meaningless?
RE the type should be obvious from the name: Well, it often is, but not necessarily. And that, I think, is the point. If I see, for example, "hireDate", I'd probably assume that's a date. But is it an internal date object, or is it a string? In Java it might be a Date or it might be a Calendar. Sure, if I see "customerName", then barring the possibility that the variable name is a complete lie, I think I can safely assume that it is not an integer or a date. It is probably a string. But it might be a text box. Or for that matter, it might be an enum that is used to identify customer name versus address versus company name. There are lots of possibilities.
Personally, I do not normally use HN. But I do use it, or something like it, when I run into cases where I have the same "logical thing" in two different formats, or when the name could be misleading.
Admin
You mean you won't let me use strAddressEmployee as a temporary work area for an XML of federal tax id? WTF?
Reuse, man!
Admin
... are still integers since they reference a memory location. They do so by specifying the start of the referenced data structure as offset from the start of a process' address space.
So, yes, char* is an integer. It refers to some (hopefully null-terminated) characters, but in itself it is an integer.
Admin
TRWTF is not a single featured comment
Admin
... are still integers since they reference a memory location. They do so by specifying the start of the referenced data structure as offset from the start of a process' address space.
So, yes, char* is an integer. It refers to some (hopefully null-terminated) characters, but in itself it is an integer.
Admin
The 'C' in "CVS" stands for "concurrent" - and not for "commented"(?) or something similar as the post suggests when it asks what the 'C' in "CVS" stands for.
So yes, some comments with instructions on what to do might go right into the code.
Admin
#5 is a WTF.
#1-#4 all tell me "this is old VB-pre-.NET code".
"Hungarian" notation used to be an alleged Best Practice.
There WAS no decent threading solution in VB6 and earlier for background work while keeping UI going.
(Oh, it was possible. But not worth it in anything normal.)
It would be a WTF to do #1-#4 today. Turns out legacy code was written with the tools available at the time.
Admin
They will archive every piece of code ever written on their servers. When you point at some code in your editor, it pops up a separate tile for every conceivable chunk of code that could possibly complete whatever it is you are attempting to code. Then you can just point/drag the tile of choice onto your editor.
What could be simpler?
Admin
Ok, let's make one thing clear: In C++ pointers are not integers. You can NOT implicitly convert from a pointer type to a non pointer type, or vice versa. You will need a reinterpret_cast for that.
I doesn't matter one bit how pointers are represented internally. They CAN NOT BE USED AS INTEGERS. The compiler will SHOUT AT YOU if you try.
So repeat after me: POINTERS ARE NOT INTEGERS IN C++.
Don't believe me? Try this:
Admin
I keep hovering my mouse over it, but nothing happens, so I don't know.
Try it in an IDE. And if you're not using a modern IDE, then you are doing it wrong.
Admin
If you are printf'ing ANYTHING you're doing C++ wrong.
Also, POINTERS ARE NOT INTEGERS (see above post).
Admin
"All modern integrated development environments display variable types on demand"
Obviously all you so-called "experts" never write any Office VBA code in Office 2010 or later?
Admin
This.
Admin
No. What does it do?
Admin
Some beer would be good right about now.
Admin
Keyword: modern. VBA was already on life support before Office 2010 ever launched. The emergence of Powershell pretty much sealed the deal, with system adminstrators now having a better scripting alternative than the old VBA scripting from the Windows Scripting Host.
Nothing new is ever going to come out of it and that includes usability enhancements. It's just maintaining the status quo for backwards compatibility. I pity the poor souls having to maintain LoB 'applications' patchworked together in Excel.
Admin
ns_I vt_use na_Hungarian no_notation npa_all da_the na_time. ns_It vt_makes da_the no_parsing a_so a_much j_easier.
-pn_Harrow.
Admin
Well, 100 getSomething-functions doesn't make me happy either. Some languages will let you use properties but in others you still need to call getters and setters explicitly... Yet it doesn't quite invoke the same emotion.
Admin
Hungarian notation is another premise in software development where the people are more important than the idea. The person who put "QR-1554-PL" into intProjectNumber should be taken out back and beaten with a garden hose. I don't care which you use, just use it consistently, and correctly.
Admin
Hungarian Notation is indeed a WTF. And every case where it might possibly convey useful information is always handled better by spelling it out in full in the variable name rather than relying on someone else's interpretation of some obscure letter code being the same. We're not living in the 80s anymore, there isn't any benefit in needlessly shortening variable names to the point of meaninglessness.
However, the real WTF is any code that calls Application.DoEvents() - fundamentally that is always a bug.
Admin
Right click on a variable and select "Quick Info".
Admin
Haha you know stuff about VBA!
Admin
VBA was never for system administrators. It was for slightly above-average office workers who knew enough to be dangerous but not enough to be truly helpful.
Admin
So what does "CVS" stand for? GIYF unless there are many results returned. There were.
As to Hungarian Notation, I find it useful. Some of the prefixes that I use are: f for flag. fClient means Is this a client? c for count. cClient means How many clients? s for size. h for handle, fh for file handle. x for index/offset.
I find HN useful if I am dealing in more than one representation. e.g. iSomething is an integer, and strSomething is the string form.
Sincerely,
Gene Wirchenko
Admin
I didn’t until the previous post peeked my curiosity.
Admin
i like hungarian for working with windows controls in vb/c#. have all labels "lbl" and textboxes "txt" and all comboboxes "cbo". then when i do my initialisation, if i have to init something for all labels for example, i can just go lbl ctrl tab, then get them in order like that so i dont forget any. then i can do the same to make sure i set a datasource on all combobox, etc.
Admin
Because having all of your variables spread throughout the list instead of grouped together makes more sense.