someone who does not trust arithmetic
-
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}i love this one!
3 in 1 :laugh: :laugh: :laugh:
-
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}i love this one!
this sort of thing can happen if you blindly follow the compiler checking messages
if (n > 16) return true; else if (n <= 16) return false;
would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. Russell -
this sort of thing can happen if you blindly follow the compiler checking messages
if (n > 16) return true; else if (n <= 16) return false;
would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. RussellOh c'mon: Use
return (n > 16);
and don't even consider thinking... :zzz: Regards Thomas -
Oh c'mon: Use
return (n > 16);
and don't even consider thinking... :zzz: Regards Thomasbool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; }
Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen. -
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}i love this one!
shadayim wrote:
i love this one!
Me too:
5
. :)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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; }
Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.Very good point - I fully agree. You gave a good example on how things like that can (and all too often will) happen in real word. But nevertheless the result is kind of 'coding horror' and urgently needs refactoring after deadline day. Regards Thomas
-
this sort of thing can happen if you blindly follow the compiler checking messages
if (n > 16) return true; else if (n <= 16) return false;
would probably report that not all paths return a value so the developer adds the else to get rid of the error. Granted with ints you should pick it up if you're not in a hurry but with more complex objects it's always possible to end up in this case without thinking. RussellUmmm....
if (n > 16) return true; else //if (n <= 16) return false;
-
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}i love this one!
I've processed that code with WinZip. The result is:
bool foo(int n) { return (n > 16); }
modified on Tuesday, November 4, 2008 4:34 PM
-
bool foo(int n)
{
if (n > 16)
return true;
else if (n <= 16)
return false;
else
return false;
}i love this one!
-
Chris Maunder wrote:
That is called "Defensive Programming" Roll eyes
Is that because many, many, many military developers use such paradigms? :rolleyes:
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; }
Coding from scratch, I agree but it's late on deadline day when someone realises that the case of n<=4 no longer applies, these kind of things can happen.Russell Jones wrote:
bool foo(int n) { if (n > 16) return true; else if (n <= 16 && n>4) return false; else if (n <= 4) return true; }
But it too would be better though as:
bool foo(int n)
{
return ((n > 16) || (n <= 4));
} -
Chris Maunder wrote:
That is called "Defensive Programming" Roll eyes
Is that because many, many, many military developers use such paradigms? :rolleyes:
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Because the developer says, "I was told to do it that way."
-
Because the developer says, "I was told to do it that way."
Indeed. :-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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Because the developer says, "I was told to do it that way."
PIEBALDconsult wrote:
Because the developer says, "I was told to do it that way."
If this is defensive programming, there must also be offensive programming and I'd kill them all - programming - because there are a lot of people out there (they call themselves also programmers, so be careful.. :-D) who give a damn on what someone else is saying, even if it might be their boss. They stick to their bad coding habits regardless of what's happening around them... Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
PIEBALDconsult wrote:
Because the developer says, "I was told to do it that way."
If this is defensive programming, there must also be offensive programming and I'd kill them all - programming - because there are a lot of people out there (they call themselves also programmers, so be careful.. :-D) who give a damn on what someone else is saying, even if it might be their boss. They stick to their bad coding habits regardless of what's happening around them... Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
:laugh: :laugh: :laugh: Great stuff!! Regards Thomas
_Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software._
-
http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
Too good. :laugh:
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.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I've processed that code with WinZip. The result is:
bool foo(int n) { return (n > 16); }
modified on Tuesday, November 4, 2008 4:34 PM
-
http://gradha.sdf-eu.org/textos/klingon_programmer.en.html[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
dan neely wrote:
http://gradha.sdf-eu.org/textos/klingon\_programmer.en.html\[^\]
One of those sounds too familiar - on our team comments are generally frowned on - especially those that may document the parameters of a function. The boss' logic? Comments frequently aren't maintained so end up out-of-date. I'm not sure about this one - I get his point, but I'd rather see a slightly off-topic comment (and correct it when I realised) than have to work out everything's purpose from scratch the first time its encountered (or when sufficient time has passed since you last looked). Then again, there seem to be no concerns about line length either. I've encountered lines of code over 1000 characters wide, so not only are there no comments, but I have to keep scrolling sideways to see the code itself. Often, the most important work is done by a function call hidden away a few screens beyond my screen estate.