Scope of variables

Adam D. Ruppe destructionator at gmail.com
Fri Jun 24 17:39:30 PDT 2011


>    void baz(local int k) {
>        void inner(local int k) {}
>    }

This is unneeded. By declaring a local variable, it's
*obviously* local - there's no point in saying local again!

Now, I've forgotten that I had a variable declared before, but
adding more stuff to the argument list wouldn't change anything,
because if I was looking at the argument list, I would have realized
the local variable was there anyway!

If D was a bad language that allowed implicit variable definitions,
it might make sense to do this, but we already declare all vars so
it adds nothing.

> void foo(int i) {} // hiding global variable

This is a good thing because you can reason about it locally. If
you declare a variable locally, you know it is going to work.

What I've taken to doing is if I definitely want to access a
class var, I'll just write this and use the dot to get to a global.

That way, it's always clear what's going on without looking
back at the function definition.


I don't want that to be required though.


More information about the Digitalmars-d mailing list