Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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