Herb Sutter briefly discusses D during interview
Ali Çehreli
acehreli at yahoo.com
Wed Jun 8 01:06:08 PDT 2011
On 06/07/2011 11:59 PM, Jonathan M Davis wrote:
> On 2011-06-07 23:43, Vladimir Panteleev wrote:
>> // Old, C/C++-like syntax - I understand this is pending deprecation
>> int a[3][4];
>> static assert(a.length == 3);
>> static assert(a[0].length == 4);
>>
>> // New D syntax
>> int[4][3] b;
>> static assert(b.length == 3);
>> static assert(b[0].length == 4);
>
> Declarations are read outward from the variable name. That's
generally right-
> to-left.
The important word there is "generally". How can we say that there is
any rule when right-to-left is only "generally"?
> Putting the array dimensions on the right side results in it being
> left-to-right, but that's not the norm.
>
> int* a; //A pointer to an int
No. The type is int* (I read it as "int pointer"), and the variable name
is a. I don't have to read it at one breath.
> int** b; //A pointer to a pointer to an int.
No. The type is int** (I read it consistently as "int pointer pointer"),
and the variable name is b.
> Left-to-right would end up being something more like this:
>
> a *int;
>
> or maybe
>
> *int a;
>
> The D syntax for static array sizes just underlines the fact that
declarations
> are generally read right-to-left because in that particular case,
it's not
> what people expect.
I don't read them that way. Perhaps we should say that the English
speakers may read right-to-left? Perhaps only when they need to
understand a very complicated declaration?
> Herb Sutter is positing that the syntax would be easier to
> grok and result in fewer errors if it were all left-to-right instead
of right-
> to-left.
D has left-to-right: Type on the left, variable on the right. Consistent.
> Yes, there are a few cases where you end up with left-to-right in C-
> based languages, because declarations are typically read outward from the
> variable name, and if that includes stuff to the right of the
variable name,
> then that part is read left-to-right, but that's the exception.
I can't remember such exceptions in D? (Well, 'alias this' comes to
mind.) Multi-dimensional array declarations and function pointer
declarations are corrected in D. That is consistent.
>
> - Jonathan M Davis
Ali
More information about the Digitalmars-d
mailing list