Naming Standards for Functions
Posted by manxman on July 5, 2016
In a good IDE (Integrated Development Environment; see Wikipedia for more details) like the one MS Access has, life can be quite easy. You can compile and the IDE will warn you of variables and function references that are incorrect.
However, if you have a lot of code (I have done apps with 10,000 or more lines) it can be challenging looking for function calls. Subroutines are easy, since the word “Call” always proceeds a use. With functions, it is not so easy. Compare the following examples of a sub call and a function call.
- Call SomeSubroutine(“123”)
- if SomeFunction(“123”) = “abc” Then
Next, compare a possible function call and a reference to an array term.
- y = SomeFunction(3)
- y = SomeArray(3)
If you need to make a change to a function (adding another parameter is a good example) you will need to change every reference to that function in your code. If you are not careful in the naming of your functions, this can present a problem finding them all.
More common to me is when reading code, am I looking at an array reference, or a function reference?
- TotalValue = ValueOfGoods(2)
Is ValueOfGoods an array variable, or a function?
Naming standards will save you.
For variables, including arrays, I usually use a prefix indicating the data type.
- strNames(3) represents a string variable
- curValueOfGoods(3) represents a currency variable
- basValueOfGoods(3) represents a function (bas = basic code) within the form
- gbasValueOfGoods(3) represents a function at the global (Modules) level, so that any form can call it
Functions I start with “f_”, as in f_SomeFunctionName. Subroutines are similarly named, s_SomeSubroutineName.
This page has an exhaustive list of prefixes. Their style is a bit different than mine, but the point is to find one that works for you and use it.
Filed under Tips and Tricks