www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Reduce redundancy in alias

reply Frank Benoit <keinfarbton googlemail.com> writes:
I use aliases in many case to import a symbol from somewhere into the 
current scope. The identifier remains the same.

For example, alias to override

class D : B {
   alias B.foo foo;
   void foo( long a ){}
}

Or i want to make constant values available from somewhere else
import WINTYPES = tango.sys.win32.types;
class OS {
   alias WINTYPES.WS_TABSTOP WS_TABSTOP;
   // 2000 more
}

I think, it would be really handy, if i could simply write
alias B.foo;

So the rule would be
"If a FQN is aliased without an alias symbol name, the last part of the 
FQN is taken as the alias symbol name."
Jun 05 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Frank Benoit wrote:
 I use aliases in many case to import a symbol from somewhere into the 
 current scope. The identifier remains the same.
 
 For example, alias to override
 
 class D : B {
   alias B.foo foo;
   void foo( long a ){}
 }
 
 Or i want to make constant values available from somewhere else
 import WINTYPES = tango.sys.win32.types;
 class OS {
   alias WINTYPES.WS_TABSTOP WS_TABSTOP;
   // 2000 more
 }
 
 I think, it would be really handy, if i could simply write
 alias B.foo;
 
 So the rule would be
 "If a FQN is aliased without an alias symbol name, the last part of the 
 FQN is taken as the alias symbol name."
I think this technically will work, but I'm a little uneasy about it.
Jun 05 2008
parent reply Paul D. Anderson <paul.d.removethis.anderson comcast.andthis.net> writes:
Walter Bright Wrote:

 Frank Benoit wrote:
 I use aliases in many case to import a symbol from somewhere into the 
 current scope. The identifier remains the same.
 
 For example, alias to override
 
 class D : B {
   alias B.foo foo;
   void foo( long a ){}
 }
 
 Or i want to make constant values available from somewhere else
 import WINTYPES = tango.sys.win32.types;
 class OS {
   alias WINTYPES.WS_TABSTOP WS_TABSTOP;
   // 2000 more
 }
 
 I think, it would be really handy, if i could simply write
 alias B.foo;
 
 So the rule would be
 "If a FQN is aliased without an alias symbol name, the last part of the 
 FQN is taken as the alias symbol name."
I think this technically will work, but I'm a little uneasy about it.
One problem is that you could intend to create an alias such as B.foo bar but mistakenly omit the alias name: B.foo and there would be no indication that an error was made until you tried to use 'bar' somewhere in the code. The error message would tell you it wasn't defined, but not where the mistake was made. An alternative would be to use a different keyword for this case, such as "brief" or "abbrev" or "unqual". (Or "sobriquet".) Then if an alias was intended but omitted it would still get flagged, and if an unqualified usage was intended but an alias was mistakenly added it would also get flagged. Paul Paul
Jun 05 2008
next sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Paul D. Anderson wrote:

 but mistakenly omit the alias name
alias B.foo $; may make the intention clearer. -manfred
Jun 05 2008
prev sibling parent Frank Benoit <keinfarbton googlemail.com> writes:
Paul D. Anderson schrieb:
 One problem is that you could intend to create an alias such as 
 
 B.foo bar
 
 but mistakenly omit the alias name:
 
 B.foo
 
 and there would be no indication that an error was made until you tried to use
'bar' somewhere in the code. The error message would tell you it wasn't
defined, but not where the mistake was made.
 
 An alternative would be to use a different keyword for this case, such as
"brief" or "abbrev" or "unqual". (Or "sobriquet".) Then if an alias was
intended but omitted it would still get flagged, and if an unqualified usage
was intended but an alias was mistakenly added it would also get flagged.
 
 Paul
 
 
 Paul
This argument can be seen also in the opposite direction. In the above example to alias the super method, if you do a typo, this will also give no compile error and make very bad runtime errors. So you can see that as even worse. class D : B { alias B.foo fooo; void foo( long a ){} }
Jun 05 2008