What's left for 1.0?
Samuel MV
samuel at jxdesigner.com
Sat Nov 18 00:17:56 PST 2006
Ok, after reading this thread and testing some code it's obvious that I
need to read again the D documentation, and after that, read it again ;-)
Probably, for most of us, there are lots of hidden little gems in D ...
and the docs need some update and/or extension to show this properly.
Maybe for v1.0 we could organize a collaborative project for 'The D
Tutorial' ...
Samuel.
Walter Bright escribió:
> Bill Baxter wrote:
>> Walter Bright wrote:
>> > C can't do any of those things.
>>
>> Sure it can.
>>
>>>> * No way to initialize a static array without counting elements
>>>> static byte[???] imageData = [...]; // i hope you like counting!
>>
>> C has no problem with this. I do it all the time:
>>
>> static const unsigned char[] = { 1,2,3,4,5,6,7, 255 };
>
> True, but that's only because C doesn't have dynamic arrays. In D,
>
> const char[] c = [ 1,2,3,4,5,6,7, 255 ];
>
> works fine, though it's a dynamic array.
>
>>>> * No way to initialize a dynamic array with a known length
>>>> byte[] imageData; imageData.length = 5; // two steps - meh
>>
>> C has no problem with this (using malloc, its own concept of "dynamic
>> arrays"):
>>
>> byte* imageData = (byte*)malloc(5*sizeof(byte));
>
> D: auto imageData = new byte[5];
>
>> A better comparison is C++, which has no problem with it's std library
>> vector class:
>>
>> vector<int> imageData(5);
>
> Yah got me there, C++ is one character shorter.
>
>
>>>> * No way to initialize array of strings
>>>> char[][] list = ["eggs","bacon","milk","break"]; //uh uh
>>
>> C can do this:
>>
>> char *list[] = { "eggs","bacon","milk","break" };
>
> So can D:
> char *list[] = [ "eggs","bacon","milk","break" ];
> char[] list[] = [ "eggs","bacon","milk","break" ];
>
>
>>>> * No way to initialize non-static struct
>>>> Point p = { x:1.0, y:2.0 }; // nope...not static
>>
>> C has no problem with that either:
>>
>> struct Point { float x, y; };
>> void foo() {
>> Point p = {1.0,2.0};
>> }
>
> True. I forgot it could (replacing "Point" with "struct Point").
More information about the Digitalmars-d
mailing list