Herb Sutter briefly discusses D during interview

Jonathan M Davis jmdavisProg at gmx.com
Tue Jun 7 23:59:27 PDT 2011


On 2011-06-07 23:43, Vladimir Panteleev wrote:
> On Wed, 08 Jun 2011 04:30:15 +0300, Jonathan M Davis <jmdavisProg at gmx.com>
> 
> wrote:
> > On 2011-06-07 17:53, Andrej Mitrovic wrote:
> >> I'm not sure what he means when he says that D doesn't simplify syntax.
> > 
> > He talked just before that about simplifying declaration syntax so that
> > it
> > reads left-to-right instead of right-to-left, and D didn't do that. For
> > instance,
> > 
> > int[4][3] a;
> > 
> > declares a static array of length three where each element of that array
> > is a
> > static array of length 4 where each of those arrays holds an integer.
> > It's
> > read right-to-left and throws people off at least some of the time.
> > Because,
> > when you go to index it, it's used left-to-right
> > 
> > auto a = i[3]; //out-of-bounds
> > 
> > Herb Sutter was suggesting that it would be a big improvement to order
> > declaration syntax such that it's read left-to-right (which apparently
> > is what
> > Pascal did, and apparently is what Go has done). D stayed closer to C
> > and C++
> > and kept the right-to-left declaration synax. That's what he was
> > referring to.
> > 
> > - Jonathan M Davis
> 
> I'm really confused by this post.
> 
> // 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. 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
int** b; //A pointer to a pointer to an int.

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

- Jonathan M Davis


More information about the Digitalmars-d mailing list