Thread overview | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 05, 2007 dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Please could D allow the following syntaxes alias dst = src; typedef dst = src; Instead of (or as well as) alias src dst; typedef src dst; I just prefer the destination on the left. Moreover, it would make for greater consistency throughout D. It would match up with assignment operators, module import renaming, and alias template specializations. |
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Janice Caron wrote:
> Please could D allow the following syntaxes
>
> alias dst = src;
> typedef dst = src;
>
> Instead of (or as well as)
>
> alias src dst;
> typedef src dst;
>
> I just prefer the destination on the left. Moreover, it would make for greater consistency throughout D. It would match up with assignment operators, module import renaming, and alias template specializations.
This has been suggested before. I'm all for it. Since types are just a kind of value in the realm of compile time evaluation, it makes sense to just have them use the same syntax. It also puts the part you care about (the symbol you're going to be using) right up front where it's easy to find. Actually that's the part I really care about. I wouldn't mind if the syntax used ':=' or something instead of '=', I'd just like to see the order reversed.
--bb
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter wrote:
> Janice Caron wrote:
>> Please could D allow the following syntaxes
>>
>> alias dst = src;
>> typedef dst = src;
>>
>> Instead of (or as well as)
>>
>> alias src dst;
>> typedef src dst;
>>
>> I just prefer the destination on the left. Moreover, it would make for greater consistency throughout D. It would match up with assignment operators, module import renaming, and alias template specializations.
>
> This has been suggested before. I'm all for it. Since types are just a kind of value in the realm of compile time evaluation, it makes sense to just have them use the same syntax. It also puts the part you care about (the symbol you're going to be using) right up front where it's easy to find. Actually that's the part I really care about. I wouldn't mind if the syntax used ':=' or something instead of '=', I'd just like to see the order reversed.
>
> --bb
I wouldn't be against it, at least as an alternative. That said, though, I've always seen alias'es and typedef's as being declerations, only directly of a symbol. In that case, they're fully consistant with other declerations taking the form 'TYPE SYMBOL'. All about perspective, I guess.
-- Chris Nicholson-Sauls
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | "Janice Caron" <caron@serenityfirefly.com> wrote in message news:mailman.91.1188982444.16939.digitalmars-d@puremagic.com... > Please could D allow the following syntaxes > > alias dst = src; > typedef dst = src; > > Instead of (or as well as) > > alias src dst; > typedef src dst; I doubt this will ever change, so to help you get used to the current syntax, here's how I think of it: int x; void function(int) fp; float[] f; These are some variable declarations, right? Now just add alias or typedef in front. alias int x; alias void function(int) fp; alias float[] f; Now they're legal aliases. Think of them like a variable declaration, except instead of making a variable, you're making a type. |
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Janice Caron wrote:
> Please could D allow the following syntaxes
>
> alias dst = src;
> typedef dst = src;
>
> Instead of (or as well as)
>
> alias src dst;
> typedef src dst;
>
> I just prefer the destination on the left. Moreover, it would make for greater consistency throughout D. It would match up with assignment operators, module import renaming, and alias template specializations.
>
>
alias src [as] dst;
typedef src [as] dst;
Yay.
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | Janice Caron Wrote:
> Please could D allow the following syntaxes
>
> alias dst = src;
> typedef dst = src;
>
> Instead of (or as well as)
>
> alias src dst;
> typedef src dst;
>
> I just prefer the destination on the left. Moreover, it would make for greater consistency throughout D. It would match up with assignment operators, module import renaming, and alias template specializations.
>
I think it was done this way to maintain consistency with C's typedefs. Personally, I like the existing syntax, but I see no reason the other shouldn't be added as an alternative.
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Janice Caron | 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; |
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Lewis | 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!
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | 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!
--bb [with apologies to Real Genius]
|
September 05, 2007 Re: dst = src rather than src dst | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | 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. :)
|
Copyright © 1999-2021 by the D Language Foundation