Qbasicnews.com

Full Version: Variables Upper or Lowercase
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Would it be better to write variables all in UPPERCASE or all in lowercase, which one would be easier to read, which stands out more etc.
I usually write variables like this:

x%
y%
Something.x%
MaxNumberOfNodes&
AngleOffX!
Array%(1 to 5)

I find that writing them in all upper-case makes them look too much like the QB commands themselves. But it's all personal preference, once compiled.

*peace*

Meg.
Here's the normal format I follow:

first of all, all variables are defined before used, and I always know what type they are (good memory I guess, hehe). Variables start in lowercase but then if they're composed of several words, each word past the first has its first word capitalized, like: myVariableIsBigAndStuff

I do constants and types in uppercase:

Const BIG_DOG_DISH = 1

Type DOGFOOD_BRANDS

and again, using memory to remember which is which. Big Grin

Functions and Subs are like Variables except every word has its first letter capitalized:

Sub ThisIsMyDogFoodSub (whichOne As DOGFOOD_BRANDS)

but as Meg says, it's all personal choice. This is just the style I personally use. Big Grin
I lowercase all my variables just to make them stick out as compared to commands, but yeah, it's all up to you, just be consistant to your own style.
Usually, CAPS are used for constants, and lower-case/upper-case mixed for identifiers. Some prefer using "_" to separate words inside the identifier, some other prefer using Caps as in Nek's examples.

In OOP languages, classes should begin with upper-case, variables with lower-case, so you know what's what: NUM will be a constant, Employee will be a class and dummyValue will be a variable.
also you can prefix the first character of the datatype to the variable name to make it easily identifiable. Something like:

Code:
DIM nVar AS INTEGER
DIM cVar AS STRING

So a person reading your program will easily understand that "nVar" is an integer/number while "cVar" is a character variable.