dst = src rather than src dst

Bill Baxter dnewsgroup at billbaxter.com
Wed Sep 5 12:26:03 PDT 2007


Janice Caron wrote:
>> so to help you get used to the current syntax, <snip>
>> Think of them like a variable declaration,
> 
> Sure, but alias is also used to importing symbols into the current 
> namespace. A good example in D 2.0+ would be
> 
> struct B
> {
>     A super_A;
>     alias super_A this;
> }
> 
> Here the intent is not to declare a variable, but to alias the symbol 
> this. Similarly
> 
>  class Derived : Base
>  {
>      int f();
>      alias f f;
>  }
> 
> Which brings the implementations of f defined in Base into Derived. 

> On a 
> similar note:
> 
> alias std.path.join join;
> 
> might be used to disambiguate between std.path.join and std.string.join. 
> In all of these cases, you are /not/ declaring a variable, you are 
> pulling symbol definitions into the current namespace, so your mneumonic 
> doesn't work. I'm not knocking it, mind. I'm just saying these would be 
> more readable as (for example)
> 
> alias join = std.path.join;
> 

This reminds me that this:

import foo = std.foo;

is already valid syntax for declaring an alias.  It's basically (perhaps 
even exactly?) equivalent to typing:

  static import std.foo;
  alias std.foo foo;

That syntax would make even more sense if it were a shortcut for

  static import std.foo;
  alias foo = std.foo;


Mainly though, I think assignment syntax would make code that uses 
generic programming easier to read.  Look at snippets like this (from 
std.bind):

alias DerefFunc!(AllBoundArgs.type[argI]).RetType FuncRetType;
alias DerefFunc!(AllBoundArgs.type[argI]).DynParams FuncDynParams;

or

alias dynArgTypes!(
	i,
	sliceOffTuple!(FuncParams, 1).res,
	Tuple!(BoundArgs.type[1..$]),
	minParamsLeft-1
	).res tmp;

The thing that you're declaring, the thing that's going to be important 
in the code that follows, gets lost.

I think these are significantly easier to read as:

alias FuncRetType = DerefFunc!(AllBoundArgs.type[argI]).RetType;
alias FuncDynParams = DerefFunc!(AllBoundArgs.type[argI]).DynParams;

or

alias tmp = dynArgTypes!(
	i,
	sliceOffTuple!(FuncParams, 1).res,
	Tuple!(BoundArgs.type[1..$]),
	minParamsLeft-1
	).res;


Because it puts the thing you care about up front where it's easy to see.

--bb



More information about the Digitalmars-d mailing list