Thread overview
A scoping operator
May 01, 2004
Matthew
May 01, 2004
Roel Mathys
May 01, 2004
Andy Friesen
May 02, 2004
Phill
May 02, 2004
J Anderson
May 02, 2004
Jeroen van Bemmel
May 01, 2004
One of the things I've wanted in C++ for a long time is the ability to be able to use scope in a similar vein to file-system location. In other words, I would like to be able to have the following

    ::X - refers to X in global scope
    :X - refers to X in local scope
    ::::X - refers to X in next most local scope

(only with better thought-out syntax)

What I'm interested in are people's thoughts for whether this would be nice in D, and suggestions for syntax.



May 01, 2004
Matthew wrote:

> One of the things I've wanted in C++ for a long time is the ability to be able to
> use scope in a similar vein to file-system location. In other words, I would like
> to be able to have the following
> 
>     ::X - refers to X in global scope
>     :X - refers to X in local scope
>     ::::X - refers to X in next most local scope
> 
> (only with better thought-out syntax)
> 
> What I'm interested in are people's thoughts for whether this would be nice in D,
> and suggestions for syntax.
> 
> 
> 

I think ':' and "::" are not used for the moment in D,
maybe there are other uses for these?
e.g. slicing ;-)

bye
roel
May 01, 2004
Matthew wrote:

> One of the things I've wanted in C++ for a long time is the ability to be able to
> use scope in a similar vein to file-system location. In other words, I would like
> to be able to have the following
> 
>     ::X - refers to X in global scope
>     :X - refers to X in local scope
>     ::::X - refers to X in next most local scope
> 
> (only with better thought-out syntax)
> 
> What I'm interested in are people's thoughts for whether this would be nice in D,
> and suggestions for syntax.

I'm not sure I see a need for this.  There should only ever be three scopes: module, class, and local, all of which can be accessed via distinct syntax.  Further, D forbids locals from shadowing 'outer' locals in nested scopes.

 -- andy
May 02, 2004
"Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c70phi$112a$1@digitaldaemon.com...
> One of the things I've wanted in C++ for a long time is the ability to be
able to
> use scope in a similar vein to file-system location. In other words, I
would like
> to be able to have the following
>
>     ::X - refers to X in global scope
>     :X - refers to X in local scope
>     ::::X - refers to X in next most local scope
>
> (only with better thought-out syntax)
>
> What I'm interested in are people's thoughts for whether this would be
nice in D,
> and suggestions for syntax.
>
>
This would be a good idea for people that would
use it no doubt.
But I can say that I wouldnt use it.
Reason:
For me it is much faster and clearer to choose another name for the
variable, and know which one I am reffering to, than to sit there and work
out which "X" I am
reffering to each time I look at the method or block of code.

But as I said, this is for my case.

Phill.




May 02, 2004
Phill wrote:

>This would be a good idea for people that would
>use it no doubt.
>But I can say that I wouldnt use it.
>Reason:
>For me it is much faster and clearer to choose another name for the
>variable, and know which one I am reffering to, than to sit there and work
>out which "X" I am
>reffering to each time I look at the method or block of code.
>
>But as I said, this is for my case.
>
>Phill.
>  
>

I had some students in a VB graphics programming class I'm tutoring.  It took me ages to convince them that the dot meant a different variable.  In the end I just renamed it.

-- 
-Anderson: http://badmama.com.au/~anderson/
May 02, 2004
"Phill" <phill@pacific.net.au> wrote in message news:c71std$2oug$1@digitaldaemon.com...
>
> "Matthew" <matthew.hat@stlsoft.dot.org> wrote in message news:c70phi$112a$1@digitaldaemon.com...
>> One of the things I've wanted in C++ for a long time is the ability to be
> able to
>> use scope in a similar vein to file-system location. In other words, I
> would like
>> to be able to have the following
>>
>>     ::X - refers to X in global scope
>>     :X - refers to X in local scope
>>     ::::X - refers to X in next most local scope
>>
>> (only with better thought-out syntax)
>>
>> What I'm interested in are people's thoughts for whether this would be
> nice in D,
>> and suggestions for syntax.
>>
>>
> This would be a good idea for people that would
> use it no doubt.
> But I can say that I wouldnt use it.
> Reason:
> For me it is much faster and clearer to choose another name for the
> variable, and know which one I am reffering to, than to sit there and work
> out which "X" I am
> reffering to each time I look at the method or block of code.
>
> But as I said, this is for my case.
>
> Phill.
>

I agree, this feature would encourage bad coding practices. Recommendation should be to use distinct names for variables as a rule, only in the most trivial and obviously non-conflicting (lazy programmer's) case should it be reluctantly endoursed.

Perhaps the compiler should even emit warnings when variable names hide other variables in outer scopes. It should be able to work in a mode where this practice causes the program not to compile, such that companies can enforce it as a quality standard (I am thinking of a compiler switch here)