Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Hungarian Notation taken too far

  • You cannot reply to this topic
9 replies to this topic

#1 mhagain   Crossbones+   -  Reputation: 8284

Like
7Likes
Like

Posted 26 March 2013 - 08:46 AM

Saw this once in some crufty old VBScript code:

 

Variant vntBlah = DoSomething ()

 

For why this is even worse than usual, the punchline is here.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9299

Like
0Likes
Like

Posted 26 March 2013 - 05:12 PM

Good old Variants.. you never know what they really are. Delphi had those too (along with the more standard data types) but they are just confusing to use.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 GeneralQuery   Crossbones+   -  Reputation: 1263

Like
1Likes
Like

Posted 26 March 2013 - 05:21 PM

"Blah" isn't descriptive enough, varVariable should do the trickph34r.png



#4 Hodgman   Moderators   -  Reputation: 31938

Like
1Likes
Like

Posted 26 March 2013 - 07:18 PM

That's not far enough! All code that uses vntBlah should be contained in a string that's eval'ed, so the prefix can be replaced with the appropriate type whenever it's used!!!

For serious though: I always have the urge to point out that this isnt real Hungarian notation; it's microsoft's pervertion, 'systems Hungarian'.

#5 frob   Moderators   -  Reputation: 22783

Like
3Likes
Like

Posted 26 March 2013 - 07:31 PM

For those who apparently missed it, the old VBScript had exactly one data type: Variant.

With exactly one data type there is no point to attempting to mark what type it is.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#6 BGB   Crossbones+   -  Reputation: 1554

Like
0Likes
Like

Posted 27 March 2013 - 03:44 PM

Good old Variants.. you never know what they really are. Delphi had those too (along with the more standard data types) but they are just confusing to use.

 

I guess a question can be asked here:

is a language with both static types and variants:

A, a statically typed language with variants as a sub-type;

B, a dynamically typed language with optional explicit type-specialization.

 

or, does it depend more on what magic goes on within the implementation?... (more values as tagged or untagged?...)

or, on the declaration syntax?... ("var x; var y:int;" vs "var x; int y;").

or, edge-case behavior (say, "long" only able to directly encode +-(2^61) and having to sometimes escape-code values outside this range, or very large/small doubles sometimes losing several bits of precision?... as a result of internal conversions to/from variant).

 

(in my case, this is one of those unanswered questions regarding whether to classify my script-language as statically or dynamically typed... then again, compared with other similar languages, it would probably be classified as statically typed, despite the frequent use of dynamic types in many places...).

 

 

I guess this sort of fits in with whether one indicates the type of a variant in a variable name:

is a variant the absence of type, or instead its own type within a collection of other types?...

 

(well, along with the whole matter of whether objects or variants are the conceptual root-type for the type-system, ...).


Edited by cr88192, 27 March 2013 - 03:59 PM.


#7 Sik_the_hedgehog   Crossbones+   -  Reputation: 1834

Like
1Likes
Like

Posted 27 March 2013 - 07:08 PM

Considering you're normally supposed to use non-Variant types, I'd say it falls under A.

 

Also ugh, I completely hate Hungarian notation, and that it's misused doesn't help. If you're going to use it then at least use it properly! (it's supposed to indicate what kind of data is stored (e.g. pxWidth would mean width in pixels), not what type of variable is it).


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#8 BGB   Crossbones+   -  Reputation: 1554

Like
0Likes
Like

Posted 27 March 2013 - 08:33 PM

Considering you're normally supposed to use non-Variant types, I'd say it falls under A.

 

Also ugh, I completely hate Hungarian notation, and that it's misused doesn't help. If you're going to use it then at least use it properly! (it's supposed to indicate what kind of data is stored (e.g. pxWidth would mean width in pixels), not what type of variable is it).

 

yeah, makes sense.

 

at least in my case (with my scripting language) using explicitly declared types can help significantly WRT things like performance, and also makes the compiler/interpreter better able to give useful errors and warnings, so this itself may be reason to use it, and likely puts things more in the statically-typed camp.

 

this is even if internally, tagged references are still often used, knowing the types often allows much cheaper logic to be used (allowing doing things directly, without all the type-checking and dynamic-dispatch and similar getting in the way).

 

...

 

so, you saying you don't like things like "LPCSTR szaStr;" or "DWORD dwSz;"?...



#9 Hodgman   Moderators   -  Reputation: 31938

Like
2Likes
Like

Posted 27 March 2013 - 08:52 PM


Also ugh, I completely hate Hungarian notation, and that it's misused doesn't help. If you're going to use it then at least use it properly! (it's supposed to indicate what kind of data is stored (e.g. pxWidth would mean width in pixels), not what type of variable is it).

so, you saying you don't like things like "LPCSTR szaStr;" or "DWORD dwSz;"?...
Yes, that's not actually Hungarian notation. That's some perversion created by someone at Microsoft who misunderstood the original idea. Within Microsoft they call this incorrect version "systems Hungarian" and the correct usage "apps Hungarian".
In the former you prefix with primitive/data-structure types, in the latter you prefix with semantic types (this length is in meters, this string uses HTML encoded characters, this 'count' is how many columns there are, etc).

#10 Sik_the_hedgehog   Crossbones+   -  Reputation: 1834

Like
0Likes
Like

Posted 27 March 2013 - 09:13 PM

Yep, pretty much. Generally I'd prefer if the name of the variable and the context by itself would be enough (if it isn't then you may want to rethink the design to make things clear enough). I guess Hungarian notation makes sense with complex projects handling all sorts of data (though in those cases I'd opt for more explicit variable names instead), but fake Hungarian notation is just a complete annoyance (if you can't tell the type by what the variable is supposed to do you have more serious issues), especially now that IDEs can help you look up the types of variables (so you don't need to do it in the source code at all).


Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.





PARTNERS