Thread overview | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 31, 2006 C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
<< I don't know if this has been discussed before, but I don't remember seeing any discussion about it. If it has been, please direct me to one of the old threads that discussed it. >> I noticed that D supports the klumsy C-Style declarations, like int (*x[5])[3]; // x is an array of 5 pointers to arrays of 3 ints I hate them! To be honest, I never understood them; never tried to. This example is taken from the docs, and I really don't understand how does it make x an array of 5 pointers to arrays of 3 ints!! D has nicer syntax, int[3]*[5] x; // x is an array of 5 pointers to arrays of 3 ints I can't say I understand how it works, but when I read the description, is makes a lot of sense. It reads right to left: [5] array of size 5 * pointer(s) [3] array of size 3 int int(s) array of 5 pointers to array of 3 ints! The only reason I don't understand it right away is because I don't like nested complex declarations like this anyway, so I never tried to learn how to declare them. However, the D syntax makes alot of sense. Consider for example this C-Style declaration: int (*x)(char); VS this D-Style declaration: int function(char) x; Why does D support int (*x)(char); anyway?! Since D has a more intelligent way of declaring the same things, the C-Style syntax is unnecessarily redundant IMHO. My understanding is that it's supported to attract the C/C++ people and get them familiarized with D quickly. But, does this mean that C-Style declarations are gonna stay with D forever? I personally would like to see them gone. but that's not for me to decide. I mean, isn't the C-Style declaration syntax considered to be a design flaw in the original C? If so, does D really need to carry it out in order to attract C/C++ people? That seems to be (to me) totally against the philosophy of D. So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point? |
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy wrote: > << I don't know if this has been discussed before, but I don't remember seeing any discussion about it. If it has been, please direct me to one of the old threads that discussed it. >> > > I noticed that D supports the klumsy C-Style declarations, like > > int (*x[5])[3]; // x is an array of 5 pointers to arrays of 3 ints > > I hate them! > To be honest, I never understood them; never tried to. This example is taken from the docs, and I really don't understand how does it make x an array of 5 pointers to arrays of 3 ints!! > > D has nicer syntax, > int[3]*[5] x; // x is an array of 5 pointers to arrays of 3 ints > [...] > > Since D has a more intelligent way of declaring the same things, the C-Style syntax is unnecessarily redundant IMHO. > > My understanding is that it's supported to attract the C/C++ people and get them familiarized with D quickly. > > But, does this mean that C-Style declarations are gonna stay with D forever? > > I personally would like to see them gone. but that's not for me to decide. [...] > So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point? > > IIRC the c style types are for convenience when porting from C. I think a better solution would be a type translator tool. Give it a listing of types in C and it gives you the same type in D (and vise versa). I would like to see them go also. |
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy escribió:
> << I don't know if this has been discussed before, but I don't remember seeing any discussion about it. If it has been, please direct me to one [snip]
I do understand C style declarations now but *only* through years of awful experiences and they are abominable. So I'll have to agree 100% with its removal if it were my decision. I'm C/C++ programmer and I didn't need that to get attracted to D, in fact, on the contrary its clearer syntax is one of the most attractive points. I'd stay with C++ if D had the same ugly syntax (as flat as it sounds).
--
Tom;
|
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom | I vote for this too. |
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | Hasan Aljudy wrote:
>
> So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point?
I'm hoping they will be deprecated before 1.0. While this may mean a small amount of extra work porting headers, I think it's worthwhile.
Sean
|
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | Sean Kelly wrote:
> Hasan Aljudy wrote:
>>
>> So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point?
>
> I'm hoping they will be deprecated before 1.0. While this may mean a small amount of extra work porting headers, I think it's worthwhile.
I left them in because they do not cause any ambiguities or trouble with the D declaration syntax. It also significantly reduces the amount of work needed to translate code to D. I don't see a compelling reason to remove them; just don't use them if you don't like them.
|
March 31, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote: > Sean Kelly wrote: > >> Hasan Aljudy wrote: >> >>> >>> So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point? >> >> >> I'm hoping they will be deprecated before 1.0. While this may mean a small amount of extra work porting headers, I think it's worthwhile. > > > I left them in because they do not cause any ambiguities or trouble with the D declaration syntax. It also significantly reduces the amount of work needed to translate code to D. I don't see a compelling reason to remove them; just don't use them if you don't like them. http://www.digitalmars.com/d/faq.html#q3 from http://www.digitalmars.com/d/overview.html "Major Goals of D [...] * Make D substantially easier to implement a compiler for than C++." If people don't want it, then it just adds unnecessarily to the task of making a compiler. |
April 01, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> Sean Kelly wrote:
>
>> Hasan Aljudy wrote:
>>
>>>
>>> So Walter, I would like to please hear your opinion/decision about C-Style declarations; are they here to stay? or will they be deprecated at some point?
>>
>>
>> I'm hoping they will be deprecated before 1.0. While this may mean a small amount of extra work porting headers, I think it's worthwhile.
>
>
> I left them in because they do not cause any ambiguities or trouble with the D declaration syntax. It also significantly reduces the amount of work needed to translate code to D. I don't see a compelling reason to remove them; just don't use them if you don't like them.
I think it kinda does.
in C/C++, the following is valid declarations:
typedef int foo;
int(x); //OK, declares x as int
foo(y); //OK, declares y as foo
in D, we get this:
alias int bar;
typedef int foo;
int(x); // OK, declares x as int
foo(y); // OK!!
bar(z); // OK!!
int main()
{
.y = 10; // ok
.z = 20; // ok
int(x); // OK, declares x as int
foo(y); // Error!!
bar(z); // Error!!
return 0;
}
why is foo(y) allowed at the global scope? and why is it disallowed at local scope?!!
|
April 01, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> Walter Bright wrote:
>> Sean Kelly wrote:
>>> Hasan Aljudy wrote:
>>>
>>>> So Walter, I would like to please hear your opinion/decision
>>>> about C-Style declarations; are they here to stay? or will they
>>>> be deprecated at some point?
>>>
>>> I'm hoping they will be deprecated before 1.0. While this may
>>> mean a small amount of extra work porting headers, I think it's
>>> worthwhile.
>>
>> I left them in because they do not cause any ambiguities or trouble
>> with the D declaration syntax. It also significantly reduces the amount of work needed to translate code to D. I don't see a
>> compelling reason to remove them; just don't use them if you don't
>> like them.
>
> http://www.digitalmars.com/d/faq.html#q3
>
> from http://www.digitalmars.com/d/overview.html
>
> "Major Goals of D [...] * Make D substantially easier to implement a
> compiler for than C++."
>
> If people don't want it, then it just adds unnecessarily to the task
> of making a compiler.
Count me in for the removal.
(I do know "some" people find them handy, but this particular detail does not stand in line with other D differences from C/C++ of lesser visibility.)
|
April 01, 2006 Re: C-Style declarations, are they here to stay?!! Walter? | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS wrote:
> If people don't want it, then it just adds unnecessarily to the task of making a compiler.
It doesn't add more than a few lines. See the code in DMD's parser.c that does it.
|
Copyright © 1999-2021 by the D Language Foundation