if...AND...else! [modified]
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
CheckValue. :wtf: :wtf: I'd also recommend
public bool IsFirstGreaterThanSecond(int nFirst, int nSecond)
{
..:)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] Donate to help Conquer Cancer[^]
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
che3358 wrote:
is better than
Certainly not better, but even MS presenters will do that because it matches what they're saying*. Unfortunately the newbies in the crowd get the idea that it is the proper way to write it. It's part of why I voted "Microsoft" to this week's poll. * That's an assumption, but I saw it several times during the VS 2008 {launch} event, I cringed every time.
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
che3358 wrote:
Folks like this way because it is better than the following way?
It's a bit easier to set a breakpoint on, is it not? Further, such code may appear in cases where (1) it had at some point been necessary to do more on the 'true' or 'false' case than is now necessary, or (2) it will likely in future be necessary to do more on the 'true' or 'false' cases than is now necessary.
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
As someone said before me, it's easier to debug, but I think this is just lack of experience in its best ;). I had my share of awkward code (true horror when compared to this) when I was junior programmer :D.
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
It may be a bit more verbose, but it's also easily understandable. The generated code may perhaps be less then optimal, but it would be a good candidate for examining the disassemblies to see if any optimisation occurs there. Even without optimisation this should have little impact unless this method is called very often. So for me it comes down to a readability versus efficiency choice and obviously the tastes are quite different there.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
This ensures the real type to be returned (
bool
)if (first > second)
return true;
else
return false;while this returns the result type of >, which may not be
bool
(in C for instance, there is no such thing asbool
, and if you create your ownbool
type, you cannot force > to return "your"bool
, hence a necessary cast to avoid a level 4 warning for casting an int on an unknown type):return first > second;
Plus returning the result of an operation is forbidden by some standards in embedded code, for instance (MISRA).
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Do not feed the troll ! - Common proverb -
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
-
It may be a bit more verbose, but it's also easily understandable. The generated code may perhaps be less then optimal, but it would be a good candidate for examining the disassemblies to see if any optimisation occurs there. Even without optimisation this should have little impact unless this method is called very often. So for me it comes down to a readability versus efficiency choice and obviously the tastes are quite different there.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
-
Thanks. I just wonder where all this will end. Today there are many more users, but they have even less knowledge than many users in 'the good old days'. But that does not keep them from thinking that everything can be done with the wave of a hand. Perhaps some already think that you need some kind of mystic powers to get those machines going :)
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
-
Thanks. I just wonder where all this will end. Today there are many more users, but they have even less knowledge than many users in 'the good old days'. But that does not keep them from thinking that everything can be done with the wave of a hand. Perhaps some already think that you need some kind of mystic powers to get those machines going :)
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'. I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
What I find even worse are some of those same users who have some "tool" (i.e. Access) that they believe makes them a programmer. And then you look at what they've done and it is magic it even works.
WarePhreak Programmers are tools to convert caffiene to code.
-
public bool CheckValue(int first, int second) { if(first > second) return true; else return false; } Folks like this way because it is better than the following way? return first > second;
modified on Friday, May 30, 2008 1:36 PM
Actually, you should scope it with parens:
return (first > second);
On the other hand, why write a function that does that when you could eliminate the overhead and stack usage by doing the comparison in the calling function?
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001