|
kakan wrote: bool isValue = (instance.Variable == 0 ? false : true);
Better still:
bool isValue = (instance.Variable != 0);
To me this is clearer.
Failure is not an option - it's built right in.
|
|
|
|
|
I would do it the same way you do.
I had two reasons for responding the way I did:
1.
I wanted the smallest possible alteration to the original code.
2.
In the past, I have given "smartcoded" examples and has been flamed for it, with comments like "unredable" and "impossible to understand". (My response that the compiler could handle my source code yielded heaps of "1" votes.)
So now I try to keep my code examples as easy to understand as possible.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
I actually posted this because I didn't see the need for the true/false test. The result of the equality test is a boolean condition, so either the item is equal to 1 (true) or it isn't (false). It just seemed that the coder had put in unnecessary code because he thought it was clever.
What made it worse, was that there were about 30 of these tests in one routine. Argggh.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Yes, under normal circumstances, it's a total waste, I agree.
The reason why I responded in the first place was that I once spent quite some time to figure out why a function (that turned out to want a VARIANT_BOOL) didn't react when I sent a (BOOL) TRUE to it.
Then I learned the difference between (BOOL) TRUE (1) and (VARIANT_BOOL) TRUE (-1).
And after that, I always test for false or not false. It can't go wrong. All versions of false *is* 0 and nothing else.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
Well, may be it's not the best way, but there could be good resons:
1) instance.Variable is a generic class you don't know the type, but you kow it supports bool operator==(int) . Assuming that an implicit conversion to bool will do the same is not obvious. (And such a conversion may be even not existent)
2) if instance.Variable is an int , assigning an int to a bool gives a warning. That code eliminates it
2a) But there is a int-to-bool native converter: the !! pseudo-oprerator
bool isValue(!!instance.Variable);
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
OK. Perhaps I'm being a bit too subtle here.
bool isVariable = (instance.Variable == 1); That's it. That's all you need to do. The check instance.Variable == 1 will only return true or false so there's no need to the ? true : false check. They are redundant.
As I've stated before - this method did about 30 of these checks. The comparison is redundant in each case.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I found this piece of code on the server side of an ASP.NET C# application. I think he was waiting for the text to change at the browser side before continuing. It didn't take me long to figure out why the page kept locking up.
while (Textbox3.Text == "")
{
}
|
|
|
|
|
varnk wrote: while (Textbox3.Text == "")
{
}
What a shame ....!!!!
|
|
|
|
|
This one gave me a good laugh:
if (index == 1 || 2)
{
...bla
}
The guy was probably on the phone while writing it.
Company policy : no access to the internet but CP
~RaGE()
|
|
|
|
|
Another reason to like C#
Perhaps also another argument for the fans of
if ( 1 == index ) { ... }
|
|
|
|
|
When I was a noob programmer I would do things like that.
if (index == 1 || index == 2)
...
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
I think that's easier to read, and less ambiguous than this since you don't have to wonder if the equals was intended or a strict less than was actually wanted.
if ((1 <= index) && (index <= 2))
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
am i losing it?
what's wrong with that?
Russell
|
|
|
|
|
You just have to be careful sometimes because some bizarre languages and/or compilers might have different precedence. I'm guessing that's what he means, to be safe I for one always put in the braces just to make sure it's doing what I want and not what it wants.
|
|
|
|
|
My example was the corrected version.
█▒▒▒▒▒██▒█▒██
█▒█████▒▒▒▒▒█
█▒██████▒█▒██
█▒█████▒▒▒▒▒█
█▒▒▒▒▒██▒█▒██
|
|
|
|
|
hence the full stop at the end of the sentence not a colon. I should check english syntax aswell as code.
Thanks for the response.
Russ
|
|
|
|
|
|
|
I saw this[^] article at thedailywtf.com and it reminded me of something.
I was reproducing a web page's functionality in a web service and in doing so had to see some error messages. One of them was along the lines of "Your request not is having some information that is required, please see a representative".
This is for an official site for an important agency so many people would have seen this throughout the years and all because someone didnt check over a non-native English speaker's work.
I've worked with a few non-native English with some projects and this seems to be an issue on many projects whether it be button names = "cancel Btton" to crazy English errors. This is not necessarily a stab at someone without a perfect grasp of the language but there needs to be better QA processes in place to catch these things.
-- modified at 15:46 Thursday 15th March, 2007
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that." - Tommy Boy "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
I agree entirely. There's not enough proofreading/editing on interfaces of any description (web site, application, etc). Mind you, I am biased since my wife is a proofreader and we offer this service to all of our clients.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
The sad part about this instance is that none of the users ever said anything.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
CleaKO wrote: The sad part about this instance is that none of the users ever said anything
Doesn't that just tell you everything you need to know about users?
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: CleaKO wrote:
The sad part about this instance is that none of the users ever said anything
Doesn't that just tell you everything you need to know about users?
Pete, CleaKO may i use the above as a sig?
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Help yourself mate.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
That's fine with me.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|