dst = src rather than src dst

Kirk McDonald kirklin.mcdonald at gmail.com
Wed Sep 5 17:39:47 PDT 2007


Bill Baxter wrote:
> Russell Lewis wrote:
> 
>> Bill Baxter wrote:
>>
>>> Robert Fraser wrote:
>>>
>>>> Russell Lewis Wrote:
>>>>
>>>>> Let's take this one step further.  Let's say that this is a typedef:
>>>>>      typedef dst = src.dup;
>>>>> while this is an alias:
>>>>>      typedef dst = src;
>>>>
>>>>
>>>> Please no!
>>>
>>>
>>> On second thought, let's take a step back again.
>>> And forward
>>> and back...
>>> and then we're cha-cha-ing!
>>
>>
>> Yeah, I felt the same way when the syntax first occurred to me: "EEK! 
>> RUN!"  But it's growing on me.  There is a certain elegance to the 
>> idea that a type is a compile-time variable, and that an alias is 
>> copying the (reference to) the type, while a typedef is creating a new 
>> type with the same contents (that is, the same semantics) as the old.
>>
>> But I still shudder when I see it. :)
> 
> 
> Well, I didn't think it was a horrible idea, just not really necessary. 
>  D already has a decent way to distinguish aliases vs definition new 
> types, and as far as I know it doesn't cause any consternation in daily 
> coding (basically you just never use the latter).
> 
> For a new language without any established conventions it might be a 
> nice idea to treat types more like values across the board, and I 
> believe there are languages that do exactly this (like lisp and python) 
> but I think it's too late for D to try to make such a big change.
> 

In Python, types /are/ values. That is, classes are objects; you can 
even define classes whose instances are classes. These are called 
metaclasses. Python's object model is so thoroughly different from D's 
that this comparison is not a useful one.

> 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.

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!

The fact that the syntax looks nothing like assignment underscores the 
fact that /it is not an assignment/. 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.)

-- 
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org



More information about the Digitalmars-d mailing list