3

Kind of as the title implies - I can understand why Apps Hungarian might crop up, but Systems Hungarian seems almost entirely pointless in a strongly-typed language. Why, then, is it so apparently prevalent in the VB world? Going back to my high school programming courses (late '00s), I had a teacher who knew nearly nothing about programming, but adhered to Systems Hungarian religiously.

I just find it odd that this naming standard persists, even in places it shouldn't (like column names in databases), and the specificity of the environments in which it does. Can anyone shed some light on this?

1 Answers1

12

Microsoft, the creator of VB, have pushed so-called "Systems Hungarian" in their documentation and examples. The Constant and Variable Naming Conventions in their Visual Basic Programmers Guide explicitly mandates Hungarian:

Variables should be prefixed to indicate their data type. Optionally, especially for large programs, the prefix can be extended to indicate the scope of the variable.

In the chapter Data Types you see examples like:

Dim intX As Integer
Dim blnRunning As Boolean

Dim objDb As Object
Set objDb = OpenDatabase("c:\Vb5\Biblio.mdb")

There are standard prefixes for all the built-in VB types. Most absurdly the prefix udt is mandated for user defined types and vnt-prefix for variants.

From Microsoft this practice has spread through coding standards, examples and tutorials, and have been adopted by the VB community at large - at least until MS realized the uselessness of Hungarian notation around the transition to VB.Net.

As for why it is used nowhere else? Because it is the stupidest and most useless idea in programming history.

JacquesB
  • 59,334
  • 2
    +1 for "Because it is the stupidest and most useless idea in programming history", though I'd contest that it's actually only the 2nd most stupidest and most useless idea in programming history, with inheritance taking 1st place ;) – David Arno Sep 05 '16 at 20:59
  • 6
    @DavidArno: I would argue that inheritance is equally as valuable as threading, and nearly as hard to use correctly. Beginners see it as the solution to all their problems (and they would be wrong, of course), but In the right hands inheritance is a very useful construct. – Bryan Oakley Sep 05 '16 at 21:03
  • 4
    Ah come on, Null should at least get an honorable mention. – candied_orange Sep 05 '16 at 21:47
  • 1
    @BryanOakley I agree with you partially. One could also blame most bad OOP authors and instructors for the overuse of inheritance. Texts and lessons present trivial data manipulation problems (most of which should actually be solved with a hash table and just a few functions) and propose inheritance (sometimes a big inheritance tree) as a good, exemplary solution. – Bernardo Sulzbach Sep 05 '16 at 22:27
  • 5
    Systems Hungarian actually makes a ton of sense in the context of VBScript, where everything is a Variant. As a former VB guy, weakly typed languages are the only place it makes sense. It certainly has no place in VB6, let alone VB.Net. – RubberDuck Sep 06 '16 at 00:15
  • 4
    There are lots of candidates for stupid and useless ideas. Yoda conditions and single point of entry / single point of return rank right up there with hungarian notation. Inheritance doesn't come even close. – David Hammen Sep 06 '16 at 08:54
  • @RubberDuck If everything's a Variant, Systems Hungarian would have you prefixing everything with v or vrnt or some such thing, which seems pretty useless. Perhaps you're thinking of Apps Hungarian, in which you prefix with types the compiler/interpreter is not aware of and/or does not enforce (e.g. prefixing one string with ss to indicate that it's a Safe String, sanitized for HTML vs prefixing with us to indicate that it's an Unsafe String, even though both are really just \0 terminated character arrays)? – 8bittree Sep 06 '16 at 16:52
  • No @8bittree. I mean Systems Hungarian, where you indicate the actual data type like iCount. Think about how useful it is to see iCount = sCount. So, yeah. Kind of Apps Hungarian, but using what are traditionally seen as Systems prefixes (i, str, etc.) because there are no damned types. – RubberDuck Sep 06 '16 at 16:55
  • @RubberDuck: Indeed the conventions mandates the vnt prefix for variants. I have updated the answer to mention this. – JacquesB Sep 07 '16 at 08:01