Top 5

KennyTM~ kennytm at gmail.com
Fri Oct 10 08:59:53 PDT 2008


Benji Smith wrote:
> Andrei Alexandrescu wrote:
>> new T[x] is a brain-dead syntax that I wish Walter hadn't imported in 
>> the first place.
> 
> Really? I think it's very valuable.
> 
> The "new T[x]" syntax lets you construct an array as an RValue. Without 
> that syntax, you have to declare an array before using it.
> 
>    // nice
>    x.setOutputBuffer(new char[64]);
> 
>    // not so nice
>    char[64] buffer;
>    x.setOutputBuffer(buffer);
> 
> Personally, I'd love to see the distinction between static arrays and 
> dynamic arrays disappear. (The compiler can do whatever it wants behind 
> the scenes, but usually I just don't care which is which, and I'd prefer 
> a unified syntax.)
> 
> I think *all* arrays should be declared like this:
> 
>    T[] array = new T[n];
> 
> If "n" is known it compile time, then D can use CTFE to create a static 
> array, and if "n" isn't known until runtime, it can create a dynamic 
> array. But as the user, I don't want to care which is which.
> 
> (And I don't see how the distinction in the type-system between T[] and 
> T[3] is useful.)
> 
> --benji

I think... “new S” creating a struct pointer while “new C” creating a 
class object reference is confusing enough...



More information about the Digitalmars-d mailing list