Scope of variables

Jonathan M Davis jmdavisProg at gmx.com
Sat Jun 25 06:17:49 PDT 2011


On 2011-06-25 05:52, bearophile wrote:
> Jonathan M Davis:
> >That's why a lot of people typically use a different naming scheme for
> >member variables (e.g. prepending them with _ or m_). As long as you're
> >smart about naming, it's really not a problem.<
> 
> I too use the leading underscore. The problem with using name tags like the
> leading underscore is lack of enforcement from the compiler (there is only
> a partial enforcement: you have to use the same name and new instance
> attributes don't pop out of existance if you assign to a wrong attribute
> name by mistake, as in Python), and lack of standards. In other code you
> often find other wans to denote member variabiles.
> 
> In Java you mostly have classes and nested classes, in C you have global
> variables and local variables (and function arguments). But in D the
> situation is more complex, you have non-lambda inner functions too, so the
> normal safeties used in C maybe are not enough. Do you use non-lambda
> inner functions often in your code? I do.
> 
> D is more complex and more powerful than both C and Java, so maybe it also
> needs more safeguards that are not needed in C and Java. You have to keep
> in mind that D code has new kinds of bugs (or higher frequency of some
> kinds of old bugs) because D has more features than C/Java.
> 
> Just trying to avoid bugs typical of C code is not enough in D! You have
> also to try to avoid D-specific bugs, coming from its differnces and new
> features.

The situation in D with regards to variable names isn't really any more 
complex in D than it is in C++, and in my experience it's virtually never a 
problem in C++. Smart variable naming makes things clear. This is a complete 
non-issue IMHO. It rarely creates bugs. Non offense, but honestly, if you're 
seeing much in the way of bugs from using the wrong variable, I have to wonder 
if you're doing something wrong.

- Jonathan M Davis


More information about the Digitalmars-d mailing list