www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - A scoping operator

reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
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
next sibling parent Roel Mathys <roel.mathys yucom.be> writes:
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
prev sibling next sibling parent Andy Friesen <andy ikagames.com> writes:
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 01 2004
prev sibling parent reply "Phill" <phill pacific.net.au> writes:
"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

 use scope in a similar vein to file-system location. In other words, I

 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

 and suggestions for syntax.

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 01 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
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 01 2004
prev sibling parent "Jeroen van Bemmel" <someone somewhere.com> writes:
"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

 use scope in a similar vein to file-system location. In other words, I

 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

 and suggestions for syntax.

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)
May 02 2004