Hungarian Notation taken too far

Started by
8 comments, last by Sik_the_hedgehog 11 years ago

Saw this once in some crufty old VBScript code:


Variant vntBlah = DoSomething ()

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

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Advertisement

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.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

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

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'.
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.

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, ...).

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.

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;"?...


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).

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.

This topic is closed to new replies.

Advertisement