Image : http://www.flickr.com
Imagine you are writing a program in Visual Basic and want to create a variable to hold the number of days of the week (strictly speaking you should probably make it a constant, but you never know how the next government will change the rules ...).
You might decide to call your intDaysWeek variable and declare it like this:
IntDaysWeek DIM AS Integer
In this case, the prefix indicates that the int variable is an integer. Other common prefixesinclude:
lng - Long
DBL - Double
str - String
Incidentally, writing IntDaysWeek variable name with a capital S, capital W is called "camel case", so called because it supports camels up and down the same way the words in capital letters like this do.
Two questions remain: this is a good idea? And why is it called Modified Hungarian notation?
To answer the second question first, the notation was originally developed by a master of Hungarian extraction, and thenthe name (even if another possible reason for the name was that in Hungary people put their names before their first name - so this article was written by Andy Brown). The bit "modified" the name derives from the fact that a variation of the original notation slgiht was then developed.
And it's a good idea? It depends on whether you like it or not. In Wise Owl tend not to use the notation for linear programming, creating disorder, techie-looking code that ismore difficult to read. Also, if you give variables meaningful names, it should be obvious what kind of data they contain. What more could contain the following variable that is not a number, for example?
NumberDaysInWeek As Integer DIM
However, we make an exception for some things (in particular controls on a user form), and may be useful to know that all the text boxes (for example) all begin with txt. This means that when you type:
me.txt
you can be sure that thecontrols whose names appear are all text boxes on the form.
No comments:
Post a Comment