devxlogo

Avoid Hungarian Notation in Public Interfaces

Avoid Hungarian Notation in Public Interfaces

Most coding standards recommend the use of Hungarian variable naming, which uses prefixes to indicate the variable’s type. However, these naming conventions usually should not be used in a component’s public interface. Consider the following function:

    Public blnCheckStuff(intStuff As Integer) As Boolean

size=3>
What if you need to change intStuff to a Variant? If you changed the name of intStuff to be consistent with its new type, code using named arguments need to change:

    bResult = blnCheckStuff(intStuff:=1)

size=3>
So, you would either have to make changes to callers to blnCheckStuff or leave the confusing and inconsistent name alone. Additionally, using Hungarian notation in a public interface betrays implementation details to the outside world, which doesn’t really follow the Encapsulation part of OO.
In most cases, a better approach would be to do a good job documenting your component and use this declaration:

    Public CheckStuff(Stuff As Integer) As Boolean

size=3>
Users of your component will still be able to tell what types to use by using Intellisense or the Object Browser.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist