Bet this algorithm never occured to anyone...
-
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
} -
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
}Wow. I just really hope it's result of changes in sales type validity rather than that someone wrote it like this from scratch :~ Still its just wrong on so many levels. Nice.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
-
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
} -
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
}surely it was coded that way to ensure extensibility?! :jig:
-
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
} -
Everyones a winner, I wonder if the unit testing picked up on this.
.net is a box of never ending treasures, every day I get find another gem.
Of course it did.
Assert.IsTrue(...);
Never fails.:laugh:Deja View - the feeling that you've seen this post before.
-
I saw (Visual Basic)
IF a=1 AND a<>2 and a<>3 and a<>4 THEN ...
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
It's that case where another thread accesses a during the call..., oh wait - you said VB:laugh:
Deja View - the feeling that you've seen this post before.
-
It's that case where another thread accesses a during the call..., oh wait - you said VB:laugh:
Deja View - the feeling that you've seen this post before.
Even in a multithreaded application the code shown didn't make any sense (at least for me). :):-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Even in a multithreaded application the code shown didn't make any sense (at least for me). :):-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
True, but I really should have put a joke icon on the post.
Deja View - the feeling that you've seen this post before.
-
Everyones a winner, I wonder if the unit testing picked up on this.
.net is a box of never ending treasures, every day I get find another gem.
Ah yes, the unit tests don't exist. :sigh: From the method comments, it seems like it should return true only for the two ifs and false for the else. I'm not even sure who to talk to about this; it was coded 3 years ago by a contractor in another country and not part of the packages we're working on. My prediction is that this baby's here to stay.
-
Ah yes, the unit tests don't exist. :sigh: From the method comments, it seems like it should return true only for the two ifs and false for the else. I'm not even sure who to talk to about this; it was coded 3 years ago by a contractor in another country and not part of the packages we're working on. My prediction is that this baby's here to stay.
-
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
}to_be_defined wrote:
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\
:badger:
-
to_be_defined wrote:
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\
:badger:
Of course not! I works doesn't it?! :laugh:
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
to_be_defined wrote:
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
Hold on, so what you're saying is that you keep looking at a function that does a few checks and returns (true) irregardless of what it checks and what happens.....and _no-one_ has changed it to remove the checks...hmm :\
:badger:
-irregardless- :laugh: That's a good one for this discussion. I bet if you changed that to simply return true all the time, it would totally break the application...
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles. -
-irregardless- :laugh: That's a good one for this discussion. I bet if you changed that to simply return true all the time, it would totally break the application...
"Quality Software since 1983!"
http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.Ihave seen much strangers things happen! :laugh:
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Of course not! I works doesn't it?! :laugh:
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
And, in many installations it would remain the way it is. In order to change code thee must be a request for an enhancement or to fix a problem. If you fix something that's 'working' and introduce a new bug you can be for the high-jump.
Paul
It probably depends on where you work and if you're the one who has to support the code in the future. If I was the one who had the support the code, I'd change it. At least then if something breaks, I'm also the one who has to fix it.
-
And, in many installations it would remain the way it is. In order to change code thee must be a request for an enhancement or to fix a problem. If you fix something that's 'working' and introduce a new bug you can be for the high-jump.
Paul
yeah, but its a function that returns true no mater what the conditions are, and judging by the calls it makes, doesnt do anything else.so..
:badger:
-
Here's one of my favourite functions in a system I'm working on right now. Every time I read this I get an overwhelming feeling of wonder...
bool CReportMethods::IsSalesTypeValid(const CXmlEntry & Entry)
{
if ( Entry.sty.GetValueAsLong() == 4L )
{
return(true);
}
else if ( Entry.sty.GetValueAsLong() == 5L )
{
return(true);
}
else
return(true);
} -
It probably depends on where you work and if you're the one who has to support the code in the future. If I was the one who had the support the code, I'd change it. At least then if something breaks, I'm also the one who has to fix it.
If it was my code, my responsibility etc, so would I. I have worked as a contractor for 25 years, and I can assure you it would NOT be changed at many places where I have worked without an RFC (request for change), cost benefit analysis, documentation, code review, test plan, version control, comment out old code and insert new, etc etc. However, if you are changing a part of the system which incorporates that particular bit of code then kill it, cus you have to do all of the above anyway. However, sometimes code you think does nothing, may do something. A slight change to the above algorithm, say that it becomes possible to drop through the code and exit without returning a return value. This throws an exception that is caught elsewhere. (That, for example, would happen with Powerbuilder 8+). Also, there may be a difference in behaviour between just returning true and looking at a passed invalid parameter (say a null pointer). For these sort of reasons, many sites will use an "if it ain't broke then don't fix it" approach. Chaning code withour permission is loose-cannon behaviour. I am not trying to support this position, all the fibres of my soul want to change code when I see it is badly written, designed or implemented. You just have to learn to sit on your coding hands.
Paul