January 06, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { return 0; } like that it should not give any warnings. no uninitialised variables. at least works that way in visual c++ (and is the rule in c++ that unused parameters just should not get a name) In article <btepa8$116p$1@digitaldaemon.com>, Ilya Minkov says... > >J Anderson wrote: >> I would like it to cause an error when parameters aren't used. But that goes against the minimum obstructions to beginners principle, Walter has talked about before. > >Does your average WinMain use all parameters? > >Mine does not. And OpenWatcom warns me about it. If i could just turn them off one by one, and not as a class! > >Now imagine it was an error! I would give up coding then. > >-eye > |
January 07, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | davepermen wrote: >int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { return 0; } > >like that it should not give any warnings. no uninitialised variables. > >at least works that way in visual c++ (and is the rule in c++ that unused >parameters just should not get a name) > > > Exactly! You specify in the code when you don't want the error to show up. >In article <btepa8$116p$1@digitaldaemon.com>, Ilya Minkov says... > > >>J Anderson wrote: >> >> >>>I would like it to cause an error when parameters aren't used. But that goes against the minimum obstructions to beginners principle, Walter has talked about before. >>> >>> >>Does your average WinMain use all parameters? >> >>Mine does not. And OpenWatcom warns me about it. If i could just turn them off one by one, and not as a class! >> >>Now imagine it was an error! I would give up coding then. >> >>-eye >> >> >> > > > > |
January 07, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | davepermen wrote: >the problem is, its not something WRONG. its just something USELESS. > >if the compiler should be able to detect usefulnes of code, it would have to be >able to understand what you really want to program. in the end, it should then >say "you want to code yet another first person shooter? thats useless.. error in >compilation" > >you get the idea.. > >for simple things, yes, we could get errors. but what if its more complex "dead >code" ? does it still has to be able to report the "bug"? > > The simple case is fine. I'd be even better if the IDE could do it and underline them like grammar errors in word. But somehow I think that'll never happen. Having said that, things like type checking could potentially be warnings in D, so who is to say what the difference is. Finding dead code in the simplest (particular) cases shouldn't be to hard to replicate in other D compiler, and will lead to less semantic bugs in code. And as we all know semantic bugs are the hardest to find. >errors only for code that is not understandable by the compiler or the running >system, a.k.a. wrong. useless code can (but doesn't have to) get optimized away. >but thats all about it. > > |
January 18, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to davepermen | "davepermen" <davepermen_member@pathlink.com> wrote in message news:btejfa$oej$1@digitaldaemon.com... > the problem is, its not something WRONG. its just something USELESS. > > if the compiler should be able to detect usefulnes of code, it would have to be > able to understand what you really want to program. in the end, it should then > say "you want to code yet another first person shooter? thats useless.. error in > compilation" > > you get the idea.. > > for simple things, yes, we could get errors. but what if its more complex "dead > code" ? does it still has to be able to report the "bug"? > > errors only for code that is not understandable by the compiler or the running > system, a.k.a. wrong. useless code can (but doesn't have to) get optimized away. > but thats all about it. The optimizer is pretty good about using global data flow analysis to detect dead code. However, it never complains about dead code. Why? Because dead code happens a lot as a side effect of common programming styles, and programmers expect it to just be optimized away. (For example, template code.) Complaining about dead code will be more of a nuisance than an aid. |
January 18, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:bucth5$19co$2@digitaldaemon.com... > > "davepermen" <davepermen_member@pathlink.com> wrote in message news:btejfa$oej$1@digitaldaemon.com... > > the problem is, its not something WRONG. its just something USELESS. > > > > if the compiler should be able to detect usefulnes of code, it would have > to be > > able to understand what you really want to program. in the end, it should > then > > say "you want to code yet another first person shooter? thats useless.. > error in > > compilation" > > > > you get the idea.. > > > > for simple things, yes, we could get errors. but what if its more complex > "dead > > code" ? does it still has to be able to report the "bug"? > > > > errors only for code that is not understandable by the compiler or the > running > > system, a.k.a. wrong. useless code can (but doesn't have to) get optimized > away. > > but thats all about it. > > The optimizer is pretty good about using global data flow analysis to detect > dead code. However, it never complains about dead code. Why? Because dead code happens a lot as a side effect of common programming styles, and programmers expect it to just be optimized away. (For example, template code.) Complaining about dead code will be more of a nuisance than an aid. I agree. Java drives me nuts when it throws a compile-time error due to unreachable code. I've never gotten that error on code I'm not deliberately cutting out during debugging. |
January 18, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote:
>The optimizer is pretty good about using global data flow analysis to detect
>dead code. However, it never complains about dead code. Why? Because dead
>code happens a lot as a side effect of common programming styles, and
>programmers expect it to just be optimized away. (For example, template
>code.) Complaining about dead code will be more of a nuisance than an aid.
>
>
>
I understand this, but:
I think there is some cases where it is obvious that the code is not what the programmer meant, which just happens to be dead code:
ie
bool x;
x != x;
These should be reported as errors by the compiler because they save the programmer from themselves.
|
January 18, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:buecc3$hvf$1@digitaldaemon.com... > Walter wrote: > > >The optimizer is pretty good about using global data flow analysis to detect > >dead code. However, it never complains about dead code. Why? Because dead code happens a lot as a side effect of common programming styles, and programmers expect it to just be optimized away. (For example, template code.) Complaining about dead code will be more of a nuisance than an aid. > I understand this, but: > I think there is some cases where it is obvious that the code is not > what the programmer meant, which just happens to be dead code: > ie > bool x; > x != x; > > These should be reported as errors by the compiler because they save the programmer from themselves. Every time I think that, it turns up somewhere in a legitimate manner <g>. |
January 21, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:buemi3$130s$1@digitaldaemon.com... > > "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:buecc3$hvf$1@digitaldaemon.com... > > Walter wrote: > > > > >The optimizer is pretty good about using global data flow analysis to > detect > > >dead code. However, it never complains about dead code. Why? Because dead > > >code happens a lot as a side effect of common programming styles, and programmers expect it to just be optimized away. (For example, template code.) Complaining about dead code will be more of a nuisance than an > aid. > > I understand this, but: > > I think there is some cases where it is obvious that the code is not > > what the programmer meant, which just happens to be dead code: > > ie > > bool x; > > x != x; > > > > These should be reported as errors by the compiler because they save the programmer from themselves. > > Every time I think that, it turns up somewhere in a legitimate manner <g>. Yeah, like what if someone overrode operator != to do some logging of every comparison? Their log would be too short. Sean |
January 21, 2004 Re: foreach inout bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Sean L. Palmer wrote:
>"Walter" <walter@digitalmars.com> wrote in message
>news:buemi3$130s$1@digitaldaemon.com...
>
>
>>"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
>>news:buecc3$hvf$1@digitaldaemon.com...
>>
>>
>>>Walter wrote:
>>>
>>>
>>>
>>>>The optimizer is pretty good about using global data flow analysis to
>>>>
>>>>
>>detect
>>
>>
>>>>dead code. However, it never complains about dead code. Why? Because
>>>>
>>>>
>dead
>
>
>>>>code happens a lot as a side effect of common programming styles, and
>>>>programmers expect it to just be optimized away. (For example, template
>>>>code.) Complaining about dead code will be more of a nuisance than an
>>>>
>>>>
>>aid.
>>
>>
>>>I understand this, but:
>>>I think there is some cases where it is obvious that the code is not
>>>what the programmer meant, which just happens to be dead code:
>>>ie
>>>bool x;
>>>x != x;
>>>
>>>These should be reported as errors by the compiler because they save the
>>>programmer from themselves.
>>>
>>>
>>Every time I think that, it turns up somewhere in a legitimate manner <g>.
>>
>>
>
>Yeah, like what if someone overrode operator != to do some logging of every
>comparison? Their log would be too short.
>
>Sean
>
>
>
Whoops I meant:
bool x;
x &= x;
Actually I was going to mention that I was talking about privative types which don't have this kinda operator overloading. With classes things would be different, although the compiler may be about to detect if an overloaded operator is being called.
|
Copyright © 1999-2021 by the D Language Foundation