Why is Hungarian Notation still so common?

Why is Hungarian Notation still so common?

christopher.pepin
Advocate Advocate
563 Views
8 Replies
Message 1 of 9

Why is Hungarian Notation still so common?

christopher.pepin
Advocate
Advocate

It seems like most of the code I see here is written in Hungarian notation and for the life of me I can't figure out why. When almost every single variable you ever use is an object what benefit are people getting from putting that o in front of everything?

0 Likes
564 Views
8 Replies
Replies (8)
Message 2 of 9

tyler.warner
Advocate
Advocate

Probably because most people who are getting started with iLogic are not familiar with programming & the samples in the API use Hungarian Notation instead of camelCase or PascalCase.

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
Message 3 of 9

christopher.pepin
Advocate
Advocate

While that makes some sense I see fresh examples coming from some of the veteran coders here.

0 Likes
Message 4 of 9

jerez.diseno
Explorer
Explorer

what is hungarian notation, if i may ask?

0 Likes
Message 5 of 9

christopher.pepin
Advocate
Advocate

It is where you prefix all your variable names with something to indicate what type of variable they are. On this forum it manifests as a sea of oVariables as every variable is an 'o'bject. Occasionally you see a 'k' pop up in case you forget that your DocumentTypeEnum variable is an enum.

 

I don't know that I have seen any of the other prefixes pop up which is why I find it so baffling that it still pops up in new code.

Message 6 of 9

dalton98
Collaborator
Collaborator

@christopher.pepin this is news to me. I always just thought you throw an 'o' in front of the variable to slightly differentiate it from what it's defining. Not speaking for everyone, but I only got into programming through Inventor so theres a lot of basic knowledge lacking

0 Likes
Message 7 of 9

A.Acheson
Mentor
Mentor

Really for me I am learning  through this forum, API help and occasional look through stack overflow and Microsoft so generally what is done in the bulk of the code, I will continue with. So if the API sample has used "o" for the object then I will continue it for simplicity. Although I have started to work without it still creeps in and I generally don't change it if helping others. I guess they could update the API help with VB.Net samples and have it removed if not needed. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 8 of 9

JelteDeJong
Mentor
Mentor

I try to follow the "C# Coding Conventions" from Microsoft. (Which uses other notations that you might be more familiar with) But most of the people here (especially the veterans) learned coding with VBA and the (outdated VBA) examples in the help files. Hungarian notation isn't the only sign that people are coming from VBA. For example, have a look at the exception handling done in some examples. You will see stuff like this:

Public Sub main
	On Error Resume Next

	Call SomeFunction()

	If Err.Number <> 0 Then
	    MsgBox(Err.Number & Space(1) & Err.Description)
	    Exit Sub 'Or Function
	End If
End Sub

Function SomeFunction()
	Throw New Exception("Serious trouble here")
End Function

This type of code predates try/catch blocks. Also, have a look at the "Call" keyword that is only needed in VBA.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 9 of 9

tyler.warner
Advocate
Advocate

I have noticed something related to this while using the iLogic browser. It may be caused by the iLogic Browser or by Grammarly which is installed on my computer. If I use camelCase naming convention, the names can be reformatted to upper case to match the Objects in the Inventor API, which could cause issues. A basic example highlighted is in Red below, "view" gets renamed to "View". This doesn't happen in Visual Studio or using Hungarian Notation.

 

--------------------

Dim document As DrawingDocument = ThisApplication.ActiveDocument
Dim sheet As Sheet = document.ActiveSheet
Dim views As DrawingViews = sheet.DrawingViews

 

For Each view As DrawingView In views
     MessageBox.Show(View.Name)
     If View.Name = "VIEW1" Then
          View.Suppressed = True
     End If
Next

If this solved your problem or answered your question, please click ACCEPT SOLUTION.
If this helped you, please click LIKE.
0 Likes