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?
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?
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.
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.
While that makes some sense I see fresh examples coming from some of the veteran coders here.
While that makes some sense I see fresh examples coming from some of the veteran coders here.
what is hungarian notation, if i may ask?
what is hungarian notation, if i may ask?
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.
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.
@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
@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
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.
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.
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.
Blog: hjalte.nl - github.com
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.
Blog: hjalte.nl - github.com
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
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
Can't find what you're looking for? Ask the community or share your knowledge.