Advice on Coding standards

G

Guest

Hello:

Is it just a good practice to fully qualify an object reference or does it
enhance performance?

For instance, if I have a Combo box, cmbMyCombo, on a form, which is better?

1. cmbMyCombo.SelectedIndex = 0
or
2. Me.cmbMyCombo.SelectedIndex = 0

Thanks for your advice.

Venkat
 
J

John Smith

Is it just a good practice to fully qualify an object reference or does it
enhance performance?

Neither. It makes the lines longer. It is actually only used at compilation
stage as it is a 'language feature' and not something you will see in the
resulting binary file. Therefore there is absolutely no performance
difference.
For instance, if I have a Combo box, cmbMyCombo, on a form, which is better?

1. cmbMyCombo.SelectedIndex = 0
or
2. Me.cmbMyCombo.SelectedIndex = 0

Neither is better. For the 1st one I'd be in doubt if it is a class or a
local variable. How can I tell that from the name?
For the 2nd line I'd say it's useless to write it out fully because it
doesn't make me much smarter except that I know now that it belongs to the
class.

In the old days with MFC, Microsoft had something they called hungarien
notation. For variables you should specify "m_" infront of the variable.
This tells that the variable is a member of the class.
It's quite commonly used on other languages like java too and these days
comes in various forms: _var1, m_var1 or var1_.

Personally I use something like m_nValue meaning an integer value belonging
to the class. If it'd be a local variable I'd use nValue instead.

-- John
 
C

Cor Ligthert

Venkat,

Me is for two things usable in one you have to, in the other it is simple

When you create a variable (object or value) in your class with the same
name as in another class that you are using, you have to use "me" to
distinct it from that other class

Me is as well very handy to use the intelisence.

It has as John already said it has no effect on your production program.

I hope this helps?

Cor
 
C

Cor Ligthert

Me is for two things usable in one you have to, in the other it is simple
handy
 
H

Herfried K. Wagner [MVP]

vvenk said:
Is it just a good practice to fully qualify an object
reference or does it enhance performance?

For instance, if I have a Combo box, cmbMyCombo,
on a form, which is better?

1. cmbMyCombo.SelectedIndex = 0
or
2. Me.cmbMyCombo.SelectedIndex = 0

Personal preference (both samples will be compiled to the same IL). I use
'Me.' because it will give me IntelliSense to select the control.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top