May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to 1100110 | On Friday, May 17, 2013 11:59:38 1100110 wrote:
> On 05/17/2013 09:35 AM, Maxim Fomin wrote:
> > If it alwalys a bad idea, compiler should not accept such code.
>
> It is not the D way to forbid you from shooting yourself in the foot.
>
> goto, catch(Throwable th), there are plenty more examples.
D will stop you from shooting yourself in the foot if it can do so in a way that doesn't actually limit you, and it does do quite a few things to make it harder to shoot yourself in the foot, but it certainly doesn't ultimately stop you from doing so. However, if it _never_ makes sense to declare a variable beginning with two underscores, I don't know why the compiler wouldn't forbid it other than the fact that it probably inserts such variables prior to when it would do the semantic analysis to check whether variables started with underscores, in which case, catching the user's variables that start with two underscores while permitting the compiler's variables could get tricky.
- Jonathan M Davis
| |||
May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | Jonathan M Davis:
> However, if it _never_ makes sense to declare a variable
> beginning with two underscores, I don't know why the compiler wouldn't forbid
> it other than the fact that it probably inserts such variables prior to when
> it would do the semantic analysis to check whether variables started with
> underscores, in which case, catching the user's variables that start with two
> underscores while permitting the compiler's variables could get tricky.
I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it.
Bye,
bearophile
| |||
May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Friday, May 17, 2013 19:19:46 bearophile wrote:
> I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it.
Oh, I'm sure that it would be possible. It's just a question of how complicated that would be and whether it's worth it given that very few programmers try and declare variables which start with two underscores.
- Jonathan M Davis
| |||
May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Friday, 17 May 2013 at 17:08:31 UTC, Jonathan M Davis wrote:
> On Friday, May 17, 2013 11:59:38 1100110 wrote:
>> On 05/17/2013 09:35 AM, Maxim Fomin wrote:
>> > If it alwalys a bad idea, compiler should not accept such code.
>>
>> It is not the D way to forbid you from shooting yourself in the foot.
>>
>> goto, catch(Throwable th), there are plenty more examples.
>
> D will stop you from shooting yourself in the foot if it can do so in a way
> that doesn't actually limit you, and it does do quite a few things to make it
> harder to shoot yourself in the foot, but it certainly doesn't ultimately stop
> you from doing so. However, if it _never_ makes sense to declare a variable
> beginning with two underscores, I don't know why the compiler wouldn't forbid
> it other than the fact that it probably inserts such variables prior to when
> it would do the semantic analysis to check whether variables started with
> underscores, in which case, catching the user's variables that start with two
> underscores while permitting the compiler's variables could get tricky.
>
> - Jonathan M Davis
The only scenario when __identifiers are needed which came to my mind is case when working with C or os implementation. Low-level implementation supposed to use '__' namespace because of practice encouraged by ISO C and other docs to reserve space for user and system specific identifiers. Probably double leading underscores should be restricted to extern declarations.
| |||
May 17, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis Attachments:
| On 05/17/2013 12:27 PM, Jonathan M Davis wrote:
> On Friday, May 17, 2013 19:19:46 bearophile wrote:
>> I think to answer this issue we need someone that knows more about the DMD compiler (as Kenji Hara). I think that if we want to forbid those variables in user code, then probably there is a way do to it.
>
> Oh, I'm sure that it would be possible. It's just a question of how complicated that would be and whether it's worth it given that very few programmers try and declare variables which start with two underscores.
>
> - Jonathan M Davis
I love how we are all basically agreeing with one another, even though we are saying such different things.
| |||
May 18, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Maxim Fomin | On Friday, 17 May 2013 at 14:35:35 UTC, Maxim Fomin wrote:
> If it alwalys a bad idea, compiler should not accept such code.
I'm pretty sure the answer is:
Compilers can have different extensions, it would be bad for a compiler to reject code which is valid by another compiler.
That said, I don't know of any rules around ignoring these as there is for pragma.
| |||
May 18, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 05/17/2013 07:19 PM, bearophile wrote:
> Jonathan M Davis:
>
>> However, if it _never_ makes sense to declare a variable
>> beginning with two underscores, I don't know why the compiler wouldn't
>> forbid
>> it other than the fact that it probably inserts such variables prior
>> to when
>> it would do the semantic analysis to check whether variables started with
>> underscores, in which case, catching the user's variables that start
>> with two
>> underscores while permitting the compiler's variables could get tricky.
>
> I think to answer this issue we need someone that knows more about the
> DMD compiler (as Kenji Hara). I think that if we want to forbid those
> variables in user code, then probably there is a way do to it.
>
> Bye,
> bearophile
It is trivial to catch them in the parser.
| |||
May 18, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Timon Gehr | Timon Gehr:
> It is trivial to catch them in the parser.
So the question is: is it right to catch them all? :-)
Bye,
bearophile
| |||
May 18, 2013 Re: Compiler bug ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 05/18/2013 11:50 AM, bearophile wrote:> Timon Gehr: > >> It is trivial to catch them in the parser. > > So the question is: is it right to catch them all? :-) I don't think so. Double underscores are reserved for the "implementation", which includes the standard library. I don't think the compiler should know that it is compiling something that is part of Phobos. It could even be a mixin that has such a variable that is implemented in Phobos. There is nothing wrong in reminder each other that a name is reserved. :) Ali | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply