| Thread overview | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
June 08, 2011 Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
There's a question related to D and Go within the first eight minutes: http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answers Andrei | ||||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | I'm not sure what he means when he says that D doesn't simplify syntax. | |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
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
| ||||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
I happen to like right-to-left, but that's just me. | ||||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 2011-06-07 17:32, Andrei Alexandrescu wrote:
> There's a question related to D and Go within the first eight minutes:
>
> http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answe rs
I find it interesting that C++0x's noexcept is still a runtime feature like exception specifications rather than going the static route that D's nothrow does. It'll be easier to implement that way, I expect, given that C++ compilers are already implementing exception specifications, but having it be statically-checked definitely has advantages. At least it's an improvement over exception specifications regardless.
From what he said about D, it definitely sounds like D is trying to go where he expects a systems programming language which could challenge C++ needs to go, though the only thing he really said in specific about D was that he thinks that we missed out on not improving the declaration and expression syntax such that it's left-to-right instead of right-to-left. That would be a pretty mind-bending change though, even if it were ultimately better. It wouldn't surprise me if it never even occurred to Walter or anyone else working on early D1 to go that route. It certainly wouldn't have ever occurred to me - particularly for the expression syntax. Thinking about it, I guess that Haskell and Scheme that way, so I've programmed in languages which were like that before, but they're functional, so they're already a huge paradigm shift, whereas C/C++ to D really isn't that big a shift. So, having a C-based language which was left-to-right would definitely throw me off, at least initially.
- Jonathan M Davis
| |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Tue, 07 Jun 2011 22:31:20 -0400, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
> On 2011-06-07 17:32, Andrei Alexandrescu wrote:
>> There's a question related to D and Go within the first eight minutes:
>>
>> http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-Answe
>> rs
>
> I find it interesting that C++0x's noexcept is still a runtime feature like
> exception specifications rather than going the static route that D's nothrow
> does. It'll be easier to implement that way, I expect, given that C++
> compilers are already implementing exception specifications, but having it be
> statically-checked definitely has advantages. At least it's an improvement
> over exception specifications regardless.
IIRC, there is already a way to statically declare that a function doesn't throw any exceptions. I think you do it with throws(). I could be wrong though, haven't used C++ in a while, and even when I did use it, I stayed away from exception specifications, having a bad experience with them.
-Steve
| |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2011-06-07 19:41, Steven Schveighoffer wrote:
> On Tue, 07 Jun 2011 22:31:20 -0400, Jonathan M Davis <jmdavisProg@gmx.com>
>
> wrote:
> > On 2011-06-07 17:32, Andrei Alexandrescu wrote:
> >> There's a question related to D and Go within the first eight minutes:
> >>
> >> http://channel9.msdn.com/Shows/Going+Deep/Herb-Sutter-C-Questions-and-An swe rs
> >
> > I find it interesting that C++0x's noexcept is still a runtime feature
> > like
> > exception specifications rather than going the static route that D's
> > nothrow
> > does. It'll be easier to implement that way, I expect, given that C++
> > compilers are already implementing exception specifications, but having
> > it be
> > statically-checked definitely has advantages. At least it's an
> > improvement
> > over exception specifications regardless.
>
> IIRC, there is already a way to statically declare that a function doesn't throw any exceptions. I think you do it with throws(). I could be wrong though, haven't used C++ in a while, and even when I did use it, I stayed away from exception specifications, having a bad experience with them.
No, those are the exception specifications that he was talking about. It's all done at runtime, and if your function violates them, it kills your program. That's why it's generally considered good practice to only ever use throws() (which indicates that nothing is thrown), and even that isn't necessarily used much. Otherwise, if anything unexpected is ever thrown, it kills your program. noexcept is essentially identical to throws(). C++ has no features for statically verifying which exceptions are or are not thrown.
- Jonathan M Davis
| |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wed, 08 Jun 2011 04:30:15 +0300, Jonathan M Davis <jmdavisProg@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); -- Best regards, Vladimir mailto:vladimir@thecybershadow.net | |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | On 2011-06-07 23:43, Vladimir Panteleev wrote:
> On Wed, 08 Jun 2011 04:30:15 +0300, Jonathan M Davis <jmdavisProg@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
| |||
June 08, 2011 Re: Herb Sutter briefly discusses D during interview | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 06/07/2011 06:30 PM, Jonathan M Davis 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. I don't think D could use right-to-left. Like this?: a int; p *int; That would be too strange for its heritage. > 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 Note that D's syntax fixes the horribly broken one of C. And contrary to popular belief, only some of C's syntax is right-to-left; notably, pointers to arrays and pointers to functions are outside-to-inside. I never read declarations from right to left. I doubt that anybody does that. "Code is not Literature". (I stole the title of tomorrow's Silicon Valley ACCU talk: http://accu.org/index.php/accu_branches/accu_usa/upcoming) Reading declarations from right-to-left is cute but there is no value in doing so. Besides, there are no "array of"s in that declaration at all. It is a coincidence that the C syntax can be read that way with the added "is a"s and "of"s. In D, type is on the left and the variable name is on the right: int i; int[4] array; int[4][3] array_of_array; That is consistent. > and throws people off at least some of the time. It must have thrown only the people who could bend their minds to somehow accept C's array syntax. > Because, > when you go to index it, it's used left-to-right What is left-to-right? Indexing does one thing: it provides access to the element with the given number. There is no left nor right in array indexing. > > auto a = i[3]; //out-of-bounds i[3] accesses the element number 3 of i (yes, with the indicated bug). There is nothing else. The type of that element is int[4] as it has been declared. This has nothing to do with left and right. > D stayed closer to C and C++ > and kept the right-to-left declaration synax. That's what he was referring to. I agree. I can't understand how D's array syntax is not seen as fixing C's broken one. Ali | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply