if bool
-
who else sees this and just laughs: if (whatever == true){ chkBox.Checked = true; }else{ chkBox.Checked = false; }
This was discussed in an earlier thread.
Kevin
-
This was discussed in an earlier thread.
Kevin
Well, this takes that a step farther; not just the test, but the setting of another boolean. Every once in a while I catch myself doing that and I have to slap my hand.
-
who else sees this and just laughs: if (whatever == true){ chkBox.Checked = true; }else{ chkBox.Checked = false; }
-
Its junk.
chkBox.Checked = whatever;
█▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██
Captain See Sharp wrote:
chkBox.Checked = whatever;
yeap you right.. you giving variable some unknown garbage value by doing so!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta Global Interface Table: An Easy Way to Marshal an Interface Pointer[new] VC Forum Q&A :- I/ IV Support CRY- Child Relief and You
-
who else sees this and just laughs: if (whatever == true){ chkBox.Checked = true; }else{ chkBox.Checked = false; }
I see it all the time. have also found this before chkBox.Checked = !(whatever == true); I think(hope) that these are normally incremental errors where the code has been tweaked bit by bit over the course of years. Boolean logic always seems to have people a bit stumped though and i'm never sure why. I've seen a few things like these in the past if (whatever || true) doStuff(); if (whatever && false) doStuff(); Russ
-
who else sees this and just laughs: if (whatever == true){ chkBox.Checked = true; }else{ chkBox.Checked = false; }
This is bad practice unless the language automatically converts between variable types. If that is the case then you could essentially assign any value to the object if you aren't careful.
Brad Australian - Bradml on "MVP Status" If this was posted in a programming board please rate my answer
-
who else sees this and just laughs: if (whatever == true){ chkBox.Checked = true; }else{ chkBox.Checked = false; }
-
I see it all the time. have also found this before chkBox.Checked = !(whatever == true); I think(hope) that these are normally incremental errors where the code has been tweaked bit by bit over the course of years. Boolean logic always seems to have people a bit stumped though and i'm never sure why. I've seen a few things like these in the past if (whatever || true) doStuff(); if (whatever && false) doStuff(); Russ
I'll admit to occasionally ending up with something like this after hacking out part of a complex conditional or breaking it into several smaller lines, and not doing a sanity check with the remaining chunks.
-- Rules of thumb should not be taken for the whole hand.
-
Its junk.
chkBox.Checked = whatever;
█▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██
i agree - i would aslo have used this
-
I see it all the time. have also found this before chkBox.Checked = !(whatever == true); I think(hope) that these are normally incremental errors where the code has been tweaked bit by bit over the course of years. Boolean logic always seems to have people a bit stumped though and i'm never sure why. I've seen a few things like these in the past if (whatever || true) doStuff(); if (whatever && false) doStuff(); Russ
I do that all the time when I debug and test extreme cases which are hard to simulate using input. I wouldn't want to be caught forgetting about them though. :)
-- For proper viewing, take red pill now