You are not logged in.

#1 27 Dec 2015 13:11

Eehixohw
Member
Registered: 25 Sep 2011
Posts: 40

Why do you use _var instead of var?

Merry Christmas guys. Best wishes to everyone.

This thing always puzzled me, why the use of

_var=abc

instead of

var=abc

AFAIK it is only a preference thing, no usage at all.

Thank you

Offline

#2 27 Dec 2015 15:47

Nexusfactor
Member
Registered: 15 Dec 2015
Posts: 8

Re: Why do you use _var instead of var?

If you're using Python, then _Var means it's supposed to be a private variable, so treat it as such.

Any other time:

There's no language-defined meaning - it's just a convention some people use to distinguish instance variables from local variables. Other variations include m_foo (and s_foo or g_foo or static variables) or mFoo; alternatively some people like to prefix the local variables (and parameters) instead of the instance variables

Offline

#3 28 Dec 2015 14:11

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Why do you use _var instead of var?

Alexander Ceed wrote:

AFAIK it is only a preference thing

Yes, in batch files there is no syntax that requires an underscore in a variable name.

It may be used because at a command prompt you can type

set _

and it will list all your variables to the screen - a useful tip for debugging.

The same technique can be used by prefixing your variables with a
and you can type set a to show them all.

Last edited by foxidrive (28 Dec 2015 14:13)

Offline

Board footer

Powered by