dst = src rather than src dst

Bill Baxter dnewsgroup at billbaxter.com
Wed Sep 5 19:20:00 PDT 2007


Kirk McDonald wrote:
> Bill Baxter wrote:

>> Just reversing the order of arguments to alias and typedef and 
>> sticking an '=' between them seems like a good value proposition to 
>> me.  Decent gain in readability and consistency, minimal pain in terms 
>> of old code breakage (assuming old-style aliases remain allowed for a 
>> while.)
>>
> 
> As to the actual proposal, I am basically indifferent. The /lack/ of the 
> equals sign makes it clear that it reads left-to-right, in my mind.

I don't think it's a matter of being difficult to remember where src and 
dest are supposed to go (though I do admit I type it backwards 
sometimes) It's just harder to read.  It's like putting the name of a 
function at the end of the function body.  Or the name of a class at the 
end.  Names and titles of things go at the beginning, not the end. 
Unless you're Paul Harvey telling "the rest of the story".

The reader of code runs across a symbol like "value_type" and needs to 
find out what that is.  I say it's harder to find it here:

alias init_base!(init_with_call_policies!(CallPoliciesT, InitT)) base;
alias InitT.n_arguments n_arguments;
alias InitT.n_defaults n_defaults;
alias InitT.signature signature;
alias pointee!(Ptr).type value_type;
alias objects.pointer_holder!(Ptr,value_type) holder;
alias objects.instance!(holder) instance_t;

than here:

alias base = init_base!(init_with_call_policies!(CallPoliciesT, InitT));
alias n_arguments = InitT.n_arguments;
alias n_defaults = InitT.n_defaults;
alias signature = InitT.signature ;
alias value_type = pointee!(Ptr).type;
alias holder = objects.pointer_holder!(Ptr,value_type);
alias instance_t = objects.instance!(holder);

The fact that it's more consistent with value assignments and with 
renamed import syntax is a nice added bonus.


> Although you might make it syntactically consistent with assignment:
> 
> int i = 10;
> alias F = Foo;
> 
> It will still be different from assignment in very fundamental ways:
> 
> i = 20; // okay
> F = Bar; // Huh?
> alias F = Baz; // Ack!

I don't get your point with that example. All types are inherently 
'final' since they are always compile time constants.  So it's just like 
saying:

final int i = 10;
i = 20; // huh?

Yeh, that's just wrong.  You can't do it.  Nothing strange about it.

> The fact that the syntax looks nothing like assignment underscores the 
> fact that /it is not an assignment/. 

I would say that the fact that the syntax looks nothing like assignment 
belies the fact that /it is an assignment/.

Think of 'alias' as meaning 'metatype', the type of types.

metatype F = Baz;

F is a new type variable (metatype) and now it equals the same thing as 
type variable Baz.


> I would classify the proposal as a 
> foolish consistency, but I wouldn't really care if it were added. 
> (Except that adding redundant syntaxes for the same operation is rarely 
> a good idea.)

Well redundancy, there is that, yes.  I suppose we could propose to 
leave D1.0 as is and change 2.0 completely.

But I think it's probably better to leave both in and just think of it 
as a backwards compatibility nod to C/C++ -- just like   foo x[3]; vs 
foo[3] x;

--bb



More information about the Digitalmars-d mailing list