Resolved Variable Naming Convention

jcardana

Old to VB6, New to VB.NET
Joined
Oct 26, 2015
Messages
43
Location
Rio Rancho, NM
Programming Experience
Beginner
I've been watching videos about cleaning up my code.
I'm using a Boolean to determine if another variable represents a file from the Computer or the USB drive.
I initially named it "CompOrUSB", with False being Computer and True being USB. My thought process is False is first and True is second (0, 1)
I 'm renaming it to "isCompOrUSB" so it's obvious that it's a boolean.
But... everyone always states "True or False" when talking about boolean situations.

So, I'm asking you... How do you interpret the variable "isCompOrUSB"? To you, which situation (Computer or USB) would TRUE represent?

Or, do you have a better method?

Thanks for your time,
Joe
 
Solution
The name is bad. That name indicates that it would be True if the file was on the computer or a USB drive and False otherwise. Something like IsLocal would be more appropriate. True means local and False means not local.
The name is bad. That name indicates that it would be True if the file was on the computer or a USB drive and False otherwise. Something like IsLocal would be more appropriate. True means local and False means not local.
 
Solution
A simple swap of True to False makes "isLocalFile" work better. Thanks!
 
The alternative would be to not use a Boolean and declare your own Enum. An Enum is a list of valid values that have text labels for human readability and numeric values under the hood for efficiency. You normally wouldn't create an Enum for just two values but it's not unknown. If you feel like your two states have equal importance - using a Boolean kinda implies that the True state is the default and the False state the alternative, but that may not accurately represent things - then an Enum may be more appropriate.
 
I'm using theses for my Series Type and File type
VB.NET:
    Private Const SeriesALL As Byte = 0  ' ORGAN SERIES FILES
    Private Const SeriesSU As Byte = 1
    Private Const SeriesA As Byte = 2
    Private Const SeriesE As Byte = 3

    Private Const ftAll As Byte = 0      ' FILE TYPES
    Private Const ftPreset As Byte = 1
    Private Const ftMusic As Byte = 2
    Private Const ftMP3 As Byte = 3
    Private Const ftMidi As Byte = 4
Since the files either come from the computer or the USB drive, I figured a boolean would be better.
 
I don't know exactly how you're using those values but you should probably be using an Enum in each case:
VB.NET:
Private Enum SeriesType
    All = 0
    SU
    A
    E
End Enum

Private Enum FileType
    All = 0
    Preset
    Music
    MP3
    Midi
End Enum
You can then declare variables, etc, as type SeriesType or FileType and use values like SeriesType.All and FileType.Preset.
 
I don't know exactly how you're using those values but you should probably be using an Enum in each case:
If you're curious, go HERE to read about the VB6 version. It's what I'm rewriting in .net.
 

Latest posts

Back
Top