Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Aug 6, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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

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)

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

Users of your component will still be able to tell what types to use by using Intellisense or the Object Browser.
Chris McCann
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date