D - foreach inout bug?
- Matthew (11/11) Jan 05 2004 this(size_type dim, value_type value)
- J Anderson (12/24) Jan 05 2004 An error should also probably also occur for:
- Matthew (6/35) Jan 05 2004 It can't be an error because, as you say, it could be in a template, and
- davepermen (9/49) Jan 06 2004 it can't be an error because in the same way this would have to be an er...
- Matthew (9/65) Jan 06 2004 That wouldn't trouble me in the slightest.
- J Anderson (14/83) Jan 06 2004 If you did:
- davepermen (4/94) Jan 06 2004 then the compiler should spit out an "You're doing useless stuff, stoopi...
- J Anderson (5/9) Jan 06 2004 [Snip]
- davepermen (12/24) Jan 06 2004 the problem is, its not something WRONG. its just something USELESS.
- J Anderson (8/21) Jan 07 2004 The simple case is fine. I'd be even better if the IDE could do it and
- Walter (13/24) Jan 17 2004 to be
- Ben Hinkle (10/38) Jan 17 2004 have
- J Anderson (9/15) Jan 18 2004 I understand this, but:
- Walter (5/19) Jan 18 2004 detect
- Sean L. Palmer (6/27) Jan 20 2004 dead
- J Anderson (8/56) Jan 21 2004 Whoops I meant:
- Ilya Minkov (6/9) Jan 06 2004 Does your average WinMain use all parameters?
- davepermen (5/14) Jan 06 2004 int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { return 0; }
- J Anderson (2/29) Jan 07 2004
this(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout is not specified. I can see the counter arguments, but this is something the compiler should warn about.
Jan 05 2004
Matthew wrote:this(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout is not specified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)
Jan 05 2004
Matthew wrote:notthis(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout isIt can't be an error because, as you say, it could be in a template, and using operations that are valid for an in parameter. I know we've don't like warnings, but leaving it to a DLint program is not the answer. Look how successful that was for C, eh? I don't know what the answer is, other than not allowing an implicit in.specified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)
Jan 05 2004
it can't be an error because in the same way this would have to be an error then, too: void func(int value) { value = 10; } this is doable, and usable. it is a copy of the value passed in. in the same way, you get a copy of the object you iterate trough. wich is useful to be manipulateable.. In article <btdg9l$23pm$1 digitaldaemon.com>, Matthew says...Matthew wrote:notthis(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout isIt can't be an error because, as you say, it could be in a template, and using operations that are valid for an in parameter. I know we've don't like warnings, but leaving it to a DLint program is not the answer. Look how successful that was for C, eh? I don't know what the answer is, other than not allowing an implicit in.specified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)
Jan 06 2004
That wouldn't trouble me in the slightest. I don't mean to be insulting to its fans, but I think the desire for such "conveniences" is juvenile. I'd be perfectly happy to type in for every in parameter. "davepermen" <davepermen_member pathlink.com> wrote in message news:bte0tu$2u5c$1 digitaldaemon.com...it can't be an error because in the same way this would have to be anerrorthen, too: void func(int value) { value = 10; } this is doable, and usable. it is a copy of the value passed in. in thesameway, you get a copy of the object you iterate trough. wich is useful to be manipulateable.. In article <btdg9l$23pm$1 digitaldaemon.com>, Matthew says...notMatthew wrote:notthis(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout isIt can't be an error because, as you say, it could be in a template, and using operations that are valid for an in parameter. I know we've don't like warnings, but leaving it to a DLint program isspecified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)the answer. Look how successful that was for C, eh? I don't know what the answer is, other than not allowing an implicit in.
Jan 06 2004
davepermen wrote:it can't be an error because in the same way this would have to be an error then, too: void func(int value) { value = 10; } this is doable, and usable. it is a copy of the value passed in. in the same way, you get a copy of the object you iterate trough. wich is useful to be manipulateable..If you did: void func(int value) { value = 10; x = value; } That is, you use the value, then it shouldn't be considered an error. But if you have: void func(int value) { value = 10; } Then your doing nothing with value. It would be optimised away. Anyway Matthew was suggesting a warning not error.In article <btdg9l$23pm$1 digitaldaemon.com>, Matthew says...Matthew wrote:notthis(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout isIt can't be an error because, as you say, it could be in a template, and using operations that are valid for an in parameter. I know we've don't like warnings, but leaving it to a DLint program is not the answer. Look how successful that was for C, eh? I don't know what the answer is, other than not allowing an implicit in.specified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)
Jan 06 2004
then the compiler should spit out an "You're doing useless stuff, stoopid" error? dunno.. i think he could spit that error out much more often:D In article <bte1oj$2vfb$1 digitaldaemon.com>, J Anderson says...davepermen wrote:it can't be an error because in the same way this would have to be an error then, too: void func(int value) { value = 10; } this is doable, and usable. it is a copy of the value passed in. in the same way, you get a copy of the object you iterate trough. wich is useful to be manipulateable..If you did: void func(int value) { value = 10; x = value; } That is, you use the value, then it shouldn't be considered an error. But if you have: void func(int value) { value = 10; } Then your doing nothing with value. It would be optimised away. Anyway Matthew was suggesting a warning not error.In article <btdg9l$23pm$1 digitaldaemon.com>, Matthew says...Matthew wrote:notthis(size_type dim, value_type value) { m_elements = new value_type[dim]; foreach(value_type element; m_elements) { element = value; // } } The assignment within the foreach loop has no effect, because inout isIt can't be an error because, as you say, it could be in a template, and using operations that are valid for an in parameter. I know we've don't like warnings, but leaving it to a DLint program is not the answer. Look how successful that was for C, eh? I don't know what the answer is, other than not allowing an implicit in.specified. I can see the counter arguments, but this is something the compiler should warn about.An error should also probably also occur for: += -= ~= ect... but then if element was an object, then an overloaded assignment operator would activate. But your right this is a trap, that I've fallen into myself. Any particular reason why it's not inout by default? PS - As we all know, be careful about using the word *warning* around big W ;)
Jan 06 2004
davepermen wrote:then the compiler should spit out an "You're doing useless stuff, stoopid" error? dunno.. i think he could spit that error out much more often:D[Snip] 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.
Jan 06 2004
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. In article <bteari$b7g$1 digitaldaemon.com>, J Anderson says...davepermen wrote:then the compiler should spit out an "You're doing useless stuff, stoopid" error? dunno.. i think he could spit that error out much more often:D[Snip] 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.
Jan 06 2004
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.
Jan 07 2004
"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 haveto beable to understand what you really want to program. in the end, it shouldthensay "you want to code yet another first person shooter? thats useless..error incompilation" you get the idea.. for simple things, yes, we could get errors. but what if its more complex"deadcode" ? does it still has to be able to report the "bug"? errors only for code that is not understandable by the compiler or therunningsystem, a.k.a. wrong. useless code can (but doesn't have to) get optimizedaway.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.
Jan 17 2004
"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...havethe problem is, its not something WRONG. its just something USELESS. if the compiler should be able to detect usefulnes of code, it wouldto beshouldable to understand what you really want to program. in the end, itthencomplexsay "you want to code yet another first person shooter? thats useless..error incompilation" you get the idea.. for simple things, yes, we could get errors. but what if its more"deadoptimizedcode" ? does it still has to be able to report the "bug"? errors only for code that is not understandable by the compiler or therunningsystem, a.k.a. wrong. useless code can (but doesn't have to) getaway.detectbut thats all about it.The optimizer is pretty good about using global data flow analysis todead 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.
Jan 17 2004
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.
Jan 18 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:buecc3$hvf$1 digitaldaemon.com...Walter wrote:detectThe optimizer is pretty good about using global data flow analysis toaid.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 anI 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>.
Jan 18 2004
"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...deadWalter wrote:detectThe optimizer is pretty good about using global data flow analysis todead code. However, it never complains about dead code. Why? BecauseYeah, like what if someone overrode operator != to do some logging of every comparison? Their log would be too short. Seanaid.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 anI 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>.
Jan 20 2004
Sean L. Palmer wrote:"Walter" <walter digitalmars.com> wrote in message news:buemi3$130s$1 digitaldaemon.com...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."J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:buecc3$hvf$1 digitaldaemon.com...deadWalter wrote:detectThe optimizer is pretty good about using global data flow analysis todead code. However, it never complains about dead code. Why? BecauseYeah, like what if someone overrode operator != to do some logging of every comparison? Their log would be too short. Seanaid.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 anI 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>.
Jan 21 2004
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
Jan 06 2004
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
Jan 06 2004
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
Jan 07 2004