Programming peeve of the Day
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
if(the_code_below_can_not_be_executed) return;
// now do what must be done -
I've no doubt that it could be more screwed up and I've seen it when I was getting payed to program. I wonder how some people get into the field and even more how they stay.
The less you need, the more you have. JaxCoder.com
Yeah, the lack of ability in some cases is amazing, and not in a good way. My boss tells a story of a former employee who made cut-n-paste an art form. Modern art form. This person appears to have never written a line of code -- everything was copied from other programs and web sites, and this person could not understand why the program would not work. In another situation I taught a COBOL programmer with 5 years experience how to program. I am not a COBOL programmer and have never compiled a single line. This is not picking on COBOL -- this guy did not understand program flow. OTOH, he was fantastic at phone support, which is where he should have been.
-
Hmm, to trying to please people who want a single exit point and clear intent when processing is completed:
if (condition)
{
goto returnStatement;
}
// Do something else:returnStatement
return;
X| :laugh: X|
That's so, so wrong on so many levels...
cheers Chris Maunder
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
-
Chris Maunder wrote:
Your rewrite is how it should be done.
Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.
Agreed! That’s what GOTO is for. :laugh:
Time is the differentiation of eternity devised by man to measure the passage of human events. - Manly P. Hall Mark Just another cog in the wheel
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
-
if (condition)
{
return;
}
else
{
// Do something else
}cheers Chris Maunder
Agreed. I like to avoid (complex) negative conditions; so I might have:
if ( negative condition as a positive) {
// continue.
else {
return;
}(Don't like your braces tho ... bad Feng Shui)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food
-
Yeah, the lack of ability in some cases is amazing, and not in a good way. My boss tells a story of a former employee who made cut-n-paste an art form. Modern art form. This person appears to have never written a line of code -- everything was copied from other programs and web sites, and this person could not understand why the program would not work. In another situation I taught a COBOL programmer with 5 years experience how to program. I am not a COBOL programmer and have never compiled a single line. This is not picking on COBOL -- this guy did not understand program flow. OTOH, he was fantastic at phone support, which is where he should have been.
My first developer job at Microsoft required me to analyze code written by a 'developer who got promoted so is no longer available. I and another dev spent hours analyzing this C language mess. Finally, after hours of analysis, we traced deep enough to get to the root of what the code was doing. Result? It returned the number 1. Yup, that is all the entire 20K lines of code did. The reason it never worked? The array this was used to dereference only had 1 element. Sheesh.
-
Chris Maunder wrote:
Your rewrite is how it should be done.
Why? It's not as clear as to what the code will do. Plus, returning from inside an if is bad form.
Why does this now come to mind? [https://static.wikia.nocookie.net/company-bumpers/images/7/7d/TCFHE-Australia-1995-Rewind.png\](https://static.wikia.nocookie.net/company-bumpers/images/7/7d/TCFHE-Australia-1995-Rewind.png) Money makes the world go round ... but documentation moves the money.